0

I have a table ("players") on which another table depends (has a foreign key that refers to players table).

I want to change a column name in this first table.

Rails db:migrate tells me:

SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "players"

While I suppose I could just remove the foreign key and try again; nowhere do I find that rails must drop a table to rename a column.

  • Because until a few months ago, to rename a column in sqlite you had to create a new table with the desired column names, copy everything to it, drop the original, and rename the new table. Usually you turn off foreign key enforcement while doing so. – Shawn Nov 17 '18 at 19:46
  • So if sqlite just copies the table, does that mean one could merely drop the foreign key constraint, instead of the foreign key as I mentioned? (referential integrity remaining, given essentially same table recreated?) – kruchkamgar Nov 17 '18 at 19:55
  • You can add or drop foreign key constraints on columns with the same process, yes. The workflow is laid out in full here: https://www.sqlite.org/lang_altertable.html (there's also a simpler method for dropping foreign keys) – Shawn Nov 17 '18 at 19:59

0 Answers0