Nullable foreignKey upon existing data

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,

Are you trying to add a ForeignKey field here or are you trying to change an existing field to be a ForeignKey?

(I generally discourage trying to do the latter. I’ve found it safer to create a new field for the ForeignKey, then write a quick script to assign the right value to that field (or do it in the shell), then proceed from that point.)

Note that the empty (or blank) string '' is not the same as Null.

Also note that a ForeignKey either refers to the Primary Key of the related table, or to another field that is defined with unique=True.

Actually I am working for a project of upgrading an existing solution in Django. So all the tables and relations are already existing in the old solution too.
Yes, the ForeignKey is the primary key of that table, which is of unique values and yes, I am changing the existing field into Foreign key.

So no solution to the current issue?

Yes, there is.

  • Create a new field for the Foreign Key, either with a default or null=True

  • Assign the appropriate references to that field

or -

  • Update the existing field with appropriate references.

Thanks for that line Ken! ++ for the solutions too !!