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

0

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 could not. When I run the command python manage.py makemigrations it returns the following error message:

  

You are trying to add a non-nullable field 'slug' to a thread without a default; we can not do that (the database needs something to populate existing rows).   Please select a fix:    1) Provide one-off default now (will be set on all existing rows)    2) Quit, and let me add default in models.py   Select an option:

Below my models.py:

link

The complete file is here:

link

Thank you.

    
asked by anonymous 03.06.2017 / 10:26

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) enter a default value for this field or "abort" the operation and correct the problem in the model. You must do one of the two, enter a default value or go in 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 make these two parameters false, 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 may be more convenient to delete the bank, migrations and rebuild it.

    
03.06.2017 / 17:27