
DataMapper automigrate has problem with Auto_increment+ index on MySQL table creation
Reported by incubaton | August 3rd, 2010 @ 09:53 AM
When you add an Integer field to a MySQL table with an auto_increment option you have to add an index or a primary key to make it works.
In DataMapper when you add a field in a table with an index
(:unique => true
for exemple), the addition of the
index is done after the CREATE TABLE in an ALTER TABLE.
Now i create my model :
CODE class TestOneTestTwo
include DataMapper::Resource storage_names[:default] = 'test_one__test_two' belongs_to :test_one, :key => true belongs_to :test_two, :key => true property :test, String, :unique => true property :id, Serial, :unique => true, :key => false
end
<<<<
There is query generated :
QUERY CREATE TABLE
test_one__test_two
(
id
INT(10) UNSIGNED AUTO_INCREMENT,
test_one_id
INT(10) UNSIGNED NOT NULL,test_two_id
INT(10) UNSIGNED NOT NULL, PRIMARY KEY(test_one_id
,test_two_id
))
ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
<<<<
As you can see, we got the id field with the AUTO_INCREMENT as
wished but no UNIQUE index so MySQL render an error :
"#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key"
(if i put a string field instead of the id field, and then have no AUTO_INCREMENT on the field, the creation of the table will be successful and the INDEX will be added in an ALTER TABLE just after the creation. )
No comments found
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »