I am stuck with this issue for longer time. Scenario is, there is a table(List) with 1000s of rows. Now I am trying to make one of its column (state) to be a foreignKey linking with another table(State) which is too having data around 20 rows.
But Django is not allowing me to proceed with making ‘migrate’ stating the error message like the below.
django django.db.utils.IntegrityError: The row in table 'List' with primary key '2' has an invalid foreign key: Dapp.List contains a value '' that does not have a corresponding value in State.state.
the field ‘state’ is nullable with the table ‘List’ and does have null values in the column for many of its rows.
But the linked ‘State’ doesn’t have any Null value.
following is the change I did in the model before trying to migrate,
State = models.ForeignKey(State, blank=True, null=True, on_delete=models.SET_NULL)
I am not getting a solution for this issue. Could you please help? Django version 4.0.5,