yii2: Migration $this->primaryKey()->unsigned() don't work for MySQL!
Showed error “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘UNSIGNED’”.
Because it generated “id
int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY UNSIGNED” invalid sql.
Need correct sql like this “id
int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY”.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 21 (16 by maintainers)
Commits related to this issue
- Add migration file example for DbSession Creating a `char` primaryKey in a migration is non-obvious. Used solution from this [issue comment](https://github.com/yiisoft/yii2/issues/10889#issuecomment-... — committed to bakavic/yii2 by bakavic 7 years ago
- Add migration file example for DbSession (#14227) [skip ci] Creating a `char` primaryKey in a migration is non-obvious. Used solution from this [issue comment](https://github.com/yiisoft/yii2/issues/... — committed to yiisoft/yii2 by bakavic 7 years ago
- update (#1) * Fixes #13945: Removed Courier New from error page fonts list since it looks bad on Linux (#13947) * Fixed phpdoc broken links to PHP manual pages [skip ci] * Fixes #10675: Added d... — committed to mixartemev/yii2 by mixartemev 7 years ago
@pptyasar , currently (<=v2.0.10):
Or add primary key later, see Migration::addPrimaryKey()
@MysteryDragon
This is how you do it:
Its because the name of
primaryKey()
itself. Should be canged to another name likeserial()
,autoIncrement()
or something else. ThenprimaryKey()
use for realPRIMARY KEY
.Then how to create pk without Auto Increment