Saturday, September 12, 2020

Re: I am getting an error message about a non-nullable field in existing rows, even though I dropped all rows via the admin interface

Interesting... did you try the email with quotes or without it....

On Saturday, September 12, 2020 at 1:43:37 PM UTC-4 mislav....@gmail.com wrote:
A question to coolguy:

What should I have done if I selected option 1? I get the Python shell and if I input a default value - let's say "te...@test.com", what else do I need to do? I tried to just provide the default value, but it wouldn't accept it, complaining that it was invalid Python (as it is). Do I need to select the existing rows from the database and set them all to have the value of the new field to the default value? If yes, how do I do this most efficiently (in code)?

Best,
Mislav

Dana subota, 12. rujna 2020. u 18:21:14 UTC+2 korisnik coolguy napisao je:
just FYI...

You didn't have to delete the db.sqllite3 file rather would have followed on-screen direction and provided a default value to persist in the existing records in your database. Later you could have edited the info through your program and make correction.

This is pretty normal situation where we added new fields/properties in our model while database has existing records. You wouldn't be able to delete the database in case you are using relational database like postgres or mysql.

Thanks

On Saturday, September 12, 2020 at 10:44:11 AM UTC-4 mislav....@gmail.com wrote:
Hey Danish,

I was able to resolve the error by deleting the db.sqlite3 file from my project root directory and all of the migrations folders from all of my apps.

Thank you for responding.

Best,
Mislav


Dana subota, 12. rujna 2020. u 14:56:13 UTC+2 korisnik mailto...@gmail.com napisao je:
you need to give default value in email. seems few records are already exist.

else delete sqllite file and try again.

On Sat, Sep 12, 2020 at 6:22 PM Mislav Jurić <mislav....@gmail.com> wrote:
Hey guys,

I added an EmailField to some of my already existing models. When I tried to run:

python manage.py makemigrations

I got the following prompt:

You are trying to add a non-nullable field 'email' to employee 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 models.py
Select an option: 

I quit the prompt (option two). Then I went ahead and commented out the new EmailField in the models I added them and I dropped all of the database rows in my entire database (not just the rows related to the models where I added the new email field; I dropped every row from every table).

Then I uncommented the new EmailField and tried to run:

python manage.py makemigrations

again, but I still get the prompt above! I selected option 1 a few times, but I'm not sure what I need to do. I tried to supply a value for that field, but the prompt is a Python shell, so I'm not sure what I need to do if I select option 1.

How do I fix this?

Best,
Mislav


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABTqP_HKzXHOAKC-y0AedjsxtBcgKLEk9Cj9J7nhgoD1EpNf%2BA%40mail.gmail.com.


--
Thanks & Regards 
  
Regards, 
Danish

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f0c98b3-bea3-4e47-977c-61323df4cf23n%40googlegroups.com.

No comments:

Post a Comment