New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixtures force autoincrement on ID column #10045
Comments
It looks like this is happening during schema generation, after the reflection is complete. The MySqlSchema class does that here. I'm pretty sure this is a backwards compatibility shim that was intended to help migrating from 2.x easier. Old fixtures would never have the |
I added this to my fixture, and it outputs
So the schema object is being built correctly. The PHP debugger shows that So I don't think this is a problem with the |
@markstory oh you're correct! This is the part here.
This forces an auto-increment if there is a primary key and no auto-increment in the schema. |
Do you think we could have this piece of logic removed in 3.4? I looked again at the code this morning, and there is no work around for it. Either we remove it or we add some way of disabling it temporary. In order to get my tests to work. I did this (for anyone else having the issue).
|
@thinkingmedia We could try removing that logic. Not generating the same primary key as the source table had/fixture defined is under the umbrella of defect. The solution for app developers would be to add |
@markstory I'm good now with my hack. We could mark this for 3.4 as a deprecated fix for 2.0 migrations. |
@markstory I was tempted to open a PR today for this. Do you think it should be changed or should we just leave it as is for now. |
I think it would be good if schema reflection resulted in the same table being generated by the fixtures. This could be something that goes into 3.5.0. I think we'd need to document this behavior change to folks who might be relying on it. |
This is a (multiple allowed):
bug
enhancement
feature-discussion (RFC)
CakePHP Version: 3.3.11
Platform and Target: Apache2, MySQL, PHP 7.1, Bash on Windows 10
What you did
Created a fixture that imports the schema.
What happened
Here is the production table named
ratings
. Notice that by design it does not have an auto-increment on the primaryID
column. This table stores film ratings and I use the numeric age as the primary key.When I created a fixture for
ratings
and used the schema import feature. The fixture manager created a table with an auto-incrementID
. This creates problems for my code.Here's the fixture table that was created.
Ignore the
AUTO_INCREMENT=20
as I dumped the create statement as the tests ran.What you expected to happen
Should not create an auto-increment column unless the source table has that attribute.
The text was updated successfully, but these errors were encountered: