[Django]-Django: Quickly deal with adding non-nullable field

3👍

Even if you have deleted all the records in that table, when running makemigrations, you’ll be asked to provide default values again. This is because you’re making a new migration file for an existing table.

One solution I can think of is to tell Django that you’re starting that app_name over again by running migrate app_name zero. This will unapply all migration files that have ever been applied to your database.

Then delete all the migration files in your app_name. And run makemigrations again. This would create a new initial migration file. Then you just apply it to your database with migrate.

As you’ve said you don’t mind deleting your data. This is even better. You don’t have to even delete any record. It will just create a new table with the same name with all the new fields and with 0 record.

Leave a comment