i have migration in postgres , sqlite, , facing problem sqlite database. same migrations 2 different databases. postgres migration ok, not sqlite. added migration altering table , adding new field.
public function up() { schema::table('retailer_products_photo_fix', function ($table) { $table->integer('currency_id')->unsigned(); $table ->foreign('currency_id') ->references('id') ->on('currency') ->onupdate('cascade') ->ondelete('cascade') ; $table->dropcolumn('currency'); }); }
but following error thrown:
general error: 1 cannot add not null column default value null
when try add nullable() field isn't created , when add default value 0 or 1 got constraint error because in related table have rows 1 , 2. how can solved?
quoting this answer daniel vassallo:
sqlite doesn't support add constraint variant of alter table command
(the source answer uses here)
so attempting alter table adding foreign key constraint isn't going work. need to:
- rename table
- recreate table updated structure (including fk constraint)
- populate new table existing data, providing values new fields
- drop old table
you can swap #1 , #2 create temporary version of table, , drop old 1 / rename new 1 @ end, that's you. may safer go route instead in case goes wrong won't have old table in renamed state @ point.
Comments
Post a Comment