[Answered ]-How do you add a unique field (non empty) field to an existing model in Django?

2👍

Here is a suggestion given on the django doc. You can give it a try. And in short it says:

  • First creat a migration that allows the new_field to be nullable;
  • Then create another migration that populates the new_field with proper values to every row in the model;
  • Then another migration which adds the not-null constraint in the column.
👤badiya

Leave a comment