I migrated this to the DB first. That worked fine, Django successfully created the new table in the database. And then I tried to make the reference via foreign key.
django.db.utils.OperationalError: (3780, "Referencing column 'customer_id' and referenced column 'id' in foreign key constraint 'TS_user_customer_id_545183b3_fk_customer_info_id' are incompatible.")
I cannot figure out why this is happening because the referencing tool is successfully referencing multiple other tools, but it will not link to this one. What is the reason for this error? And how can I fix it so that I can link the tables? Why are they incompatible?
I think you’re misunderstanding the function of the db_column parameter. It’s a reference to the column name in the User table, not the column name being referenced in the CustomerInfo model.
Yes, looks like. If the user model is changed after the first migration of the app (0001_initial), manual fixing of schemas is required since foreign keys and many-to-many relationships are affected.
That’s only true if you’re changing to a different Model. Making a change to the currently-used User model is ok.
(In other words, if you’re using the default User model and then switching to a user-defined User model you would need to follow those steps. But if you are starting with a user-defined User model, you can make changes to it as desired without taking extra steps.)
But that’s a different situation than the issue here.
For some yet-to-be-identified reason, Django migrations is not matching the data type of the related field.
My guess is that this is because the target table is managed = False.
It may be necessary to edit the migration file for this User model to force the right data type.