bizley / yii2-migration

Yii 2 Migration Creator And Updater
Apache License 2.0
291 stars 36 forks source link

[Bug] Primary Key Int Length setting to 10 instead of 11 #158

Closed hkbertoson closed 2 years ago

hkbertoson commented 2 years ago

Describe the bug If I create a table and make my primary key an Int with a length of 11. When I create a migration and then run it. It is making the primary key a length of 10 instead of 11

Expected behavior If the length if 11. It should make it 11 instead of 10

Additional context

Affected versions What version of yii2-migration are you working with? (Please remember that v1, v2, and v3 are not supported anymore) - Latest Version What is the database engine and its version? I am using mariadb:10.0

bizley commented 2 years ago

I haven't tested it with Mariadb but since it's similar to MySQL there might be a reason for that - is the column unsigned? Also remember that the number indicates only how the value will be presented, the range remains the same.

hkbertoson commented 2 years ago

Yes the column is unsigned. Where I run into issues with it is creating foreign keys. Because if I have an ID with an Int(11) but one with Int(10). It will throw an error due to not matching types.

bizley commented 2 years ago

This is expected behavior of the database. You cannot create foreign key out of not matching columns, either change all columns (primary and foreign keys) to unsigned ones or to signed ones. There is no bug here.