From 8bc2dfe4c6275c5ed548b12b0e2d5e7fd2ff074f Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sat, 18 Feb 2017 17:55:52 +0000 Subject: [PATCH] Django migrations doesn't account for PostgreSQL completely This was a weird bug to run into. Basically I changed a CharField into a ForeignKey field and ran `makemigrations` to get the job done. However, rather than doing a `RemoveField` and an `AddField`, migrations created a single `AlterField` which worked just fine in SQLite, but blew up in PostgreSQL with: psycopg2.ProgrammingError: operator class "varchar_pattern_ops" does not accept data type integer The fix was to rewrite the single migration into the two separate steps. --- src/documents/migrations/0003_sender.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/documents/migrations/0003_sender.py b/src/documents/migrations/0003_sender.py index 7a08502d0..ce2508994 100644 --- a/src/documents/migrations/0003_sender.py +++ b/src/documents/migrations/0003_sender.py @@ -47,7 +47,11 @@ class Migration(migrations.Migration): ], ), migrations.RunPython(move_sender_strings_to_sender_model), - migrations.AlterField( + migrations.RemoveField( + model_name='document', + name='sender', + ), + migrations.AddField( model_name='document', name='sender', field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='documents.Sender'),