db:automigrate fails dm 1.3.0 - beta and mysql #35

Closed
carlosacp opened this Issue Feb 14, 2012 · 7 comments

Projects

None yet

5 participants

@carlosacp

Hello,
I'm running a rails 3.2.1 project with dm-* 1.3.0.beta and using mysql database. When I run db:automigrate it fails:

Tried in a Windows and Linux environment.

Can't create table 'mytable.#sql-618_4d' (errno: 150)
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-do-adapter-d295d77f3e4b/lib/dm-do-adapter/adapter.rb:63:in execute_non_query'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-do-adapter-d295d77f3e4b/lib/dm-do-adapter/adapter.rb:63:in
block in execute'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-do-adapter-d295d77f3e4b/lib/dm-do-adapter/adapter.rb:276:in with_connection'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-do-adapter-d295d77f3e4b/lib/dm-do-adapter/adapter.rb:61:in
execute'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-constraints-67cfad8018ed/lib/data_mapper/constraints/adapters/do_adapter.rb:71:in create_relationship_
constraint'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-constraints-67cfad8018ed/lib/data_mapper/constraints/migrations/relationship.rb:19:in
auto_migrate_con
straints_up'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-constraints-67cfad8018ed/lib/data_mapper/constraints/migrations/model.rb:16:in block in auto_migrate_c
onstraints_up'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-core-3aee0ec24233/lib/dm-core/support/subject_set.rb:210:in
block in each'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-core-3aee0ec24233/lib/dm-core/support/ordered_set.rb:319:in block in each'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-core-3aee0ec24233/lib/dm-core/support/ordered_set.rb:319:in
each'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-core-3aee0ec24233/lib/dm-core/support/ordered_set.rb:319:in each'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-core-3aee0ec24233/lib/dm-core/support/subject_set.rb:210:in
each'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/dm-constraints-67cfad8018ed/lib/data_mapper/constraints/migrations/model.rb:15:in `auto_migrate_constraint

Regards,
Carlos

@snusnu
DataMapper member

iirc errno 150 is a foreign key error. have you checked if there aren't any "leftover" tables that can't be deleted due to (changed?) foreign keys?

@carlosacp

I tried it in both: an empty database and in a database with "leftover" tables.
I had the same problem in both.
someone had the same problem:
Snorby/snorby#159
and he's right: autoupgrade works, but automigrate no.

@snusnu
DataMapper member

i remember one more thing: if you declare your FK properties (integers) explicitly (i.e. not using belongs_to but property), you need to add a :min => 0 option to the integer property. Otherwise, mysql cannot match the types. Again, this might not solve your specific problem, but it's something to be aware of. Unfortunately I don't have time now to investigate further.

@dkubb
DataMapper member

@carlosacp What version of MySQL are you using? Are you able to create a single file with an example of something that fails for you? Then we can run it here and see if it still fails, and start debugging it. Right now it's difficult to determine if it's something local to your system, or an actual bug in the software, so having a reproduction would be a great first step.

@eltiare

FWIW, here's a workaround to get similar behavior:

a = User.repository.adapter
a.execute('SET FOREIGN_KEY_CHECKS = 0')
a.execute('DROP DATABASE your_app_test')
a.execute('CREATE DATABASE your_app_test')
a.execute('SET FOREIGN_KEY_CHECKS = 1')
a.execute('USE your_app_test')
DataMapper.auto_upgrade!

@dkubb
DataMapper member

@snusnu the min/max issues with the FKs is now resolved on dm-core master. There was a problem with the inference algorithm, and it would copy all the other properties of the PK into the FK, other than the min/max values. It now includes them, so the PK and FK should match up properly on MySQL.

@tpitale
DataMapper member

I'm going to close this, as it seems to be resolved on dm-core master.

@tpitale tpitale closed this Jul 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment