When testing with SQLite, I’ve met several problems with migrations.
Cannot add a NOT NULL column with default value NULL
When you have a migration that changes columns in a table:
When running this migration on MySQL everything is OK. But when running the same migration on SQlite, it throws the following error:
This was very frustrating for me. But after googling this error, I’ve found that it is SQLite feature. When adding a table from scratch,
you can specify NOT NULL field. However, you can’t do this when adding a column. SQLite’s specification says you have to have a default for this.
So, to fix it our migration should be the following:
Errors when dropping column
Here we have changed our migration:
When rolling back this migration it will fail in the following error:
To fix it we can specify an array of columns when dropping:
@ 2021. All rights reserved.
If you've got any feedback, comments or just want to chat you can get in
touch via Twitter or email.