Problem when migrating with Python and Django: no such column: forum_thread.Slug

Asked

Viewed 303 times

-1

I have this problem in my code:

OperationalError at /admin/forum/thread/ no such column: forum_thread.slug

I’ve tried to make a million changes and I couldn’t. When I turn the command python manage.py makemigrations returns the following error message:

You are trying to add a non-nullable field 'Slug' to thread 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) 2) Quit, and Let me add a default in models.py Select an option:

Down with my models.py:

https://github.com/MarcusWiilo/Django-Aplications/blob/master/pro_final/pro_final/forum/models.py

The complete file is here:

https://github.com/MarcusWiilo/Django-Aplications/tree/master/pro_final

Thanks.

1 answer

0

The message says that you are adding a "non-nullable" field, in a database that already has records, but you have not set a default value for that field. The message gives you 2 options: 1) to inform a default value for this field or to "abort" the operation and fix the problem in the model. You must do one of the two, enter a default value or go to your model and add in the field:

slug = models.SlugField(...., null=True, blank=True)

With this you can create the field, then make the necessary changes, and then false these two parameters, if necessary.

Or you could have entered a default value for the field, like this:

slug = models.SlugField(...., default='Valor default blah blah')

If the bank is testing, it might be more convenient to exclude the bank, the migrations and rebuild it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.