padrino / padrino-framework

Padrino is a full-stack ruby framework built upon Sinatra.
http://www.padrinorb.com
MIT License
3.37k stars 510 forks source link

rake migrate failing #101

Closed jvatic closed 14 years ago

jvatic commented 14 years ago

Every time I try and run padrino rake dm:migrate I get the following:

=> Executing Rake dm:migrate ...
 == Performing Up Migration #1: create_accounts
   CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50), "surname" VARCHAR(50), "email" VARCHAR(50), "crypted_password" VARCHAR(50), "salt" VARCHAR(50), "role" VARCHAR(50))
rake aborted!
table "accounts" already exists
/Library/Ruby/Gems/1.8/gems/padrino-core-0.9.9/lib/padrino-core/cli/rake.rb:9:in `init'
(See full trace by running task with --trace)

and with --trace:

=> Executing Rake dm:migrate --trace ...
** Invoke dm:migrate (first_time)
** Invoke dm:migrate:up (first_time)
** Invoke dm:migrate:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute dm:migrate:load
** Execute dm:migrate:up
 == Performing Up Migration #1: create_accounts
   CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50), "surname" VARCHAR(50), "email" VARCHAR(50), "crypted_password" VARCHAR(50), "salt" VARCHAR(50), "role" VARCHAR(50))
rake aborted!
table "accounts" already exists
/Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:61:in `execute_non_query'
/Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:61:in `execute'
/Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:269:in `with_connection'
/Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:59:in `execute'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:83:in `execute'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:136:in `say_with_time'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:136:in `say_with_time'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:82:in `execute'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:88:in `create_table'
./db/migrate/001_create_accounts.rb:3
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:57:in `call'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:57:in `perform_up'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:136:in `say_with_time'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:136:in `say_with_time'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration.rb:56:in `perform_up'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration_runner.rb:57:in `migrate_up!'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration_runner.rb:55:in `each'
/Library/Ruby/Gems/1.8/gems/dm-migrations-0.10.2/lib/dm-migrations/migration_runner.rb:55:in `migrate_up!'
/Users/jesse/.bundle/ruby/1.8/bundler/gems/padrino-framework-da42868283fca4941ccdcfc887a5cde85a7e730a-master/padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb:28
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/Library/Ruby/Gems/1.8/gems/padrino-core-0.9.9/lib/padrino-core/cli/rake.rb:9:in `init'
/Library/Ruby/Gems/1.8/gems/padrino-core-0.9.9/lib/padrino-core/cli/base.rb:49:in `rake'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/task.rb:33:in `send'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/task.rb:33:in `run'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:109:in `invoke'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:116:in `call'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:116:in `invoke'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor.rb:137:in `start'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/base.rb:378:in `start'
/Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor.rb:124:in `start'
/Library/Ruby/Gems/1.8/gems/padrino-core-0.9.9/bin/padrino:20
/usr/bin/padrino:19:in `load'
/usr/bin/padrino:19

Is there any way of fixing this?

DAddYE commented 14 years ago

Super strange, I think this is a know dm issue. Can you try to drop and recreate the db and then run migrations?

Thanks!

jvatic commented 14 years ago

I deleted the db and ran padrino rake dm:create and the migration still does the exact same thing.

DAddYE commented 14 years ago

sqlite or mysql?

jvatic commented 14 years ago

sqlite

DAddYE commented 14 years ago

Ok, thanks, can you tell me wich step I need to do for reproduce the problem?

This for me work fine:

padrino-gen project foo -d datamapper -b
cd foo
padrino-gen admin
padrino-gen rake dm:migrate
padrino-gen model post title:string description:string
padrino-gen rake dm:migrate
padrino-gen admin_page post
padrino-gen rake seed
padrino start
rm -rf ../foo
cd ..
jvatic commented 14 years ago

I can't seem to recreate this issue, I do however get a different error when executing padrino-gen admin_page post

$ padrino-gen admin_page post
=> Located unlocked Gemfile for development
/Library/Ruby/Gems/1.8/gems/padrino-admin-0.9.9/lib/padrino-admin/generators/orm.rb:17:in `initialize': Model post was not found! (Padrino::Admin::Generators::OrmError)
    from /Library/Ruby/Gems/1.8/gems/padrino-admin-0.9.9/lib/padrino-admin/generators/admin_page.rb:33:in `new'
    from /Library/Ruby/Gems/1.8/gems/padrino-admin-0.9.9/lib/padrino-admin/generators/admin_page.rb:33:in `create_controller'
    from /Library/Ruby/Gems/1.8/gems/padrino-admin-0.9.9/lib/padrino-admin/generators/admin_page.rb:32:in `each'
    from /Library/Ruby/Gems/1.8/gems/padrino-admin-0.9.9/lib/padrino-admin/generators/admin_page.rb:32:in `create_controller'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/task.rb:33:in `send'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/task.rb:33:in `run'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:109:in `invoke'
    from /Library/Ruby/Gems/1.8/gems/padrino-gen-0.9.9/lib/padrino-gen.rb:53:in `map'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/core_ext/ordered_hash.rb:73:in `each'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:118:in `map'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:118:in `invoke'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/group.rb:36:in `start'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/base.rb:378:in `start'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/group.rb:29:in `start'
    from /Library/Ruby/Gems/1.8/gems/padrino-gen-0.9.9/lib/padrino-gen/generators/cli.rb:42:in `setup'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/task.rb:33:in `send'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/task.rb:33:in `run'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:109:in `invoke'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `map'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/core_ext/ordered_hash.rb:75:in `each'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:118:in `map'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/invocation.rb:118:in `invoke'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/group.rb:36:in `start'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/base.rb:378:in `start'
    from /Library/Ruby/Gems/1.8/gems/thor-0.13.4/lib/thor/group.rb:29:in `start'
    from /Library/Ruby/Gems/1.8/gems/padrino-gen-0.9.9/bin/padrino-gen:14
    from /usr/bin/padrino-gen:19:in `load'
    from /usr/bin/padrino-gen:19
DAddYE commented 14 years ago

Mmm, iper strange

can you puts me your gem env?

jvatic commented 14 years ago
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.6
  - RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-10
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/jesse/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["http://gems.rubyforge.org/", "http://gemcutter.org/", "http://gemcutter.org/", "http://gems.github.com", "http://gems.github.com", "http://gemcutter.org"]
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/
     - http://gemcutter.org/
     - http://gemcutter.org/
     - http://gems.github.com
     - http://gems.github.com
     - http://gemcutter.org
nesquena commented 14 years ago

I have tried these steps as well:

padrino-gen project foo -d datamapper -b
cd foo
padrino-gen admin
padrino rake dm:migrate
padrino-gen model post title:string description:string
padrino rake dm:migrate
padrino-gen admin_page post
padrino rake seed
padrino start

and it seems to execute without error. The last error you got seems to suggest the Post model isnt being loaded into the environment.

jvatic commented 14 years ago

weird, I tried it again and it works. I guess the migration problem is probably caused by the padrino project being corrupt in some way and can be fixed by moving it into a new project. I have do idea how it corrupted though.

DAddYE commented 14 years ago

Ok if you can reproduce the problem reopen this ticket! Thanks!

jvatic commented 14 years ago

I managed to reproduce the problem:

$ padrino-gen project demo -t rspec -e haml -m rr -s jquery -d datamapper -c sass
      create  
      create  config/apps.rb
      create  config/boot.rb
      create  config.ru
      create  public/favicon.ico
      create  .gitignore
      create  public/images
      create  public/javascripts
      create  public/stylesheets
      create  tmp
      create  app
      create  app/app.rb
      create  app/controllers
      create  app/helpers
      create  app/views
      create  app/views/layouts/.emptydirectory
      create  .components
      create  Gemfile
Applying 'datamapper' (orm)...
      inject  Gemfile
      inject  Gemfile
      inject  Gemfile
      create  config/database.rb
      create  app/models
Applying 'rspec' (test)...
      inject  Gemfile
      create  spec/spec_helper.rb
      create  spec/spec.rake
Applying 'rr' (mock)...
      inject  Gemfile
      inject  spec/spec_helper.rb
Applying 'jquery' (script)...
      create  public/javascripts/jquery.js
      create  public/javascripts/application.js
Applying 'haml' (renderer)...
      inject  Gemfile
Applying 'sass' (stylesheet)...
      inject  Gemfile
      create  lib/sass.rb
      inject  app/app.rb
      create  app/stylesheets

=================================================================
demo is ready for development! Next, follow these steps:
=================================================================
  1) cd demo
  2) bundle install
=================================================================

Jesse-Stuarts-HackBook-Pro:Projects jesse$ cd demo
Jesse-Stuarts-HackBook-Pro:demo jesse$ bundle install
Fetching source index from http://gemcutter.org/
Using rake (0.8.7) from system gems
Using activesupport (2.3.5) from system gems
Using addressable (2.1.1) from system gems
Using bcrypt-ruby (2.1.2) from system gems
Using bundler (0.9.16) from system gems
Using daemons (1.0.10) from system gems
Using data_objects (0.10.1) from system gems
Using extlib (0.9.14) from system gems
Using dm-core (0.10.2) from system gems
Using dm-aggregates (0.10.2) from system gems
Using dm-constraints (0.10.2) from system gems
Using dm-migrations (0.10.2) from system gems
Using fastercsv (1.5.3) from bundler gems
Using json_pure (1.2.3) from bundler gems
Using dm-serializer (0.10.2) from system gems
Using dm-timestamps (0.10.2) from system gems
Using stringex (1.1.0) from system gems
Using uuidtools (2.1.1) from system gems
Using dm-types (0.10.2) from system gems
Using dm-validations (0.10.2) from system gems
Using datamapper (0.10.2) from bundler gems
Using do_sqlite3 (0.10.1.1) from system gems
Using eventmachine (0.12.10) from system gems
Using fuzzyhash (0.0.11) from system gems
Using haml (2.2.22) from bundler gems
Using i18n (0.3.6) from system gems
Using rack (1.1.0) from system gems
Using sinatra (1.0) from system gems
Using thor (0.13.4) from system gems
Using usher (0.7.1) from system gems
Using padrino-core (0.9.9) from system gems
Using padrino-gen (0.9.9) from system gems
Using padrino-helpers (0.9.9) from system gems
Using padrino-admin (0.9.9) from system gems
Using tmail (1.2.7.1) from system gems
Using padrino-mailer (0.9.9) from system gems
Using padrino (0.9.9) from system gems
Using rack-flash (0.1.1) from system gems
Using rack-test (0.5.3) from system gems
Using rr (0.10.11) from bundler gems
Using rspec (1.3.0) from system gems
Using thin (1.2.7) from bundler gems
Your bundle is complete! Use `bundle show gemname` to see where a bundled gem is installed.
demo $ padrino-gen admin
=> Located unlocked Gemfile for development
      create  admin
      create  admin/app.rb
      create  admin/controllers/base.rb
      create  admin/controllers/sessions.rb
      create  public/admin
      create  public/admin/stylesheets/base.css
      create  public/admin/stylesheets/themes/amro/style.css
      create  public/admin/stylesheets/themes/bec/style.css
      create  public/admin/stylesheets/themes/bec-green/style.css
      create  public/admin/stylesheets/themes/blue/style.css
      create  public/admin/stylesheets/themes/default/style.css
      create  public/admin/stylesheets/themes/djime-cerulean/style.css
      create  public/admin/stylesheets/themes/kathleene/style.css
      create  public/admin/stylesheets/themes/olive/style.css
      create  public/admin/stylesheets/themes/orange/style.css
      create  public/admin/stylesheets/themes/reidb-greenish/style.css
      create  public/admin/stylesheets/themes/ruby/style.css
      create  public/admin/stylesheets/themes/warehouse/style.css
      create  app/models/account.rb
      create  spec/models/account_spec.rb
      create  db/migrate/001_create_accounts.rb
      create  admin/controllers/accounts.rb
      create  admin/views/accounts/_form.haml
      create  admin/views/accounts/edit.haml
      create  admin/views/accounts/index.haml
      create  admin/views/accounts/new.haml
      inject  admin/app.rb
       force  app/models/account.rb
      create  db/seeds.rb
      create  admin/views/base/_sidebar.haml
      create  admin/views/base/index.haml
      create  admin/views/layouts/application.haml
      create  admin/views/sessions/new.haml
      inject  admin/app.rb
      append  config/apps.rb
        gsub  admin/views/accounts/_form.haml
        gsub  admin/controllers/accounts.rb

=================================================================
The admin panel has been mounted! Next, follow these steps:
=================================================================
  1) Run migrations (if necessary)
  2) Run 'padrino rake seed'
  3) Visit the admin panel in the browser at '/admin'
=================================================================

demo $ padrino rake dm:create
=> Executing Rake dm:create ...
=> Creating database 
<= dm:auto:migrate executed
demo $ padrino rake seed
=> Executing Rake seed ...
Which email do you want use for loggin into admin? demo@demo.com
Tell me the password to use: Demo

=================================================================
Account has been successfully created, now you can login with:
=================================================================
   email: demo@demo.com
   password: Demo
=================================================================
demo $ padrino-gen model post
=> Located unlocked Gemfile for development
      create  app/models/post.rb
      create  spec/models/post_spec.rb
      create  db/migrate/002_create_posts.rb
demo $ mate app/models/post.rb

added "property :title, String" to app/models/post.rb

demo $ padrino rake dm:migrate
=> Executing Rake dm:migrate ...
 == Performing Up Migration #1: create_accounts
   CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50), "surname" VARCHAR(50), "email" VARCHAR(50), "crypted_password" VARCHAR(50), "salt" VARCHAR(50), "role" VARCHAR(50))
rake aborted!
table "accounts" already exists
/Library/Ruby/Gems/1.8/gems/padrino-core-0.9.9/lib/padrino-core/cli/rake.rb:9:in `init'
(See full trace by running task with --trace)
demo $

Basically what causes the problem is manually editing a model after generating it with padrino-gen model and then running migrations.

DAddYE commented 14 years ago

Thanks so much! Now we will try your steps and made a fix (if not dm related).

achiurizo commented 14 years ago

I believe this has something to do with dm's migrate. instead of: $ padrino rake dm:migrate

use $ padrino rake dm:auto:migrate

nesquena commented 14 years ago

Actually, I would advise against auto:migrate as it is destructive. I would use

$ padrino rake dm:auto:upgrade

which does non-destructive auto migrations

nesquena commented 14 years ago

Yes, I have essentially confirmed that this works. Please let me know if it works for you.

$ padrino rake seed
$ padrino-gen model post
# added "property :title, String" to app/models/post.rb
$ padrino rake dm:auto:upgrade
$ padrino-gen admin_page post

Seems to work fine. Hope that helps. I will re-open if you are still experiencing problems.

jvatic commented 14 years ago

Yes, this works!

nesquena commented 14 years ago

Glad to hear it :)

spirallab commented 13 years ago

I am still having this problem with 0.9.14 and datamapper. I have previously created admin pages, but when I try to generate a page for the model "pass" I get:

padrino-framework-56c5d91/padrino-admin/lib/padrino-admin/generators/orm.rb:17:in `initialize': Model 'pass' could not be found! (Padrino::Admin::Generators::OrmError)

Any ideas?

I've ran: padrino rake dm:migrate and padrino rake dm:auto:upgrade

both completed without errors. But still no luck generating the page.

spirallab commented 13 years ago

Sorry, google didn't turn up this issue: http://github.com/padrino/padrino-framework/issues/issue/309

The patch there fixed my problem.