Makemigrations/migrate in django


Could anyone help me solve this problem?
I want to add data and time models in Django, but after makemigration, I got this.

**You are trying to add a non-nullable field ‘MeterReading_DateTime’ to mdm_api without a default; we can’t do that (the database needs something to populate existing rows).
Please select a fix:

  1. Provide a one-off default now (will be set on all existing rows with a null value for this column)
  2. Quit, and let me add a default in
    Select an option:**


Because it is a non-nullable field, It needs a default value to be set if there is a row without a value for that column.

The first point means, for the existing records, it will add a value for this field.
The second point means, you have to give a default value which will be used for the existing records and also for the future records (unless you change it)

Either you add a null=True, give it a one-off default value, or add a default value in your model

Answered By – Basant kumar Bhala

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published