Stackow3
Stackow3

Reputation: 61

how to change the database after changing the model?

please help, something strange happens.

I had a model:

class Feedback(models.Model):
    username = models.CharField(
        verbose_name=u"Имя", 
        max_length=100,
        blank=True,
    )
    subject = models.CharField(
        verbose_name=u"Тема", 
        max_length=100,
        blank=False,
    )   
    email = models.EmailField(
        verbose_name=u"Email", 
        max_length=100,
        blank=True,
    )       
    message = models.TextField(
        verbose_name=u'Сообщение',
        max_length=50000, 
        blank=False,
    )           
    date = models.DateTimeField(
        verbose_name=u'Дата создания',
        default=datetime.now(),
        auto_now=True,
    )

based on it, I created a feedback form. she worked. I created a few messages, and then delete all entries from the corresponding table in the database

then I changed the names of the fields:

class Feedback(models.Model):
    username_f = models.CharField(
        verbose_name=u"Имя", 
        max_length=100,
        blank=True,
    )
    subject_f = models.CharField(
        verbose_name=u"Тема", 
        max_length=100,
        blank=False,
    )   
    email_f = models.EmailField(
        verbose_name=u"Email", 
        max_length=100,
        blank=True,
    )       
    message_f = models.TextField(
        verbose_name=u'Сообщение',
        max_length=50000, 
        blank=False,
    )           
    date_f = models.DateTimeField(
        verbose_name=u'Дата создания',
        default=datetime.now(),
        auto_now=True,
    )

and made the following from the console:

(kinopom_env)kalinins@kalinins-Lenovo-Z580 ~/.virtualenvs/kinopom_project/kinopom $ python manage.py schemamigration --auto app_menu

the result was the following:

 - Deleted field username on app_menu.Feedback
 - Deleted field date on app_menu.Feedback
 ? The field 'Feedback.message' does not have a default specified, yet is NOT NULL.
 ? Since you are removing this field, you MUST specify a default
 ? value to use for existing rows. Would you like to:
 ?  1. Quit now.
 ?  2. Specify a one-off value to use for existing columns now
 ?  3. Disable the backwards migration by raising an exception; you can edit the migration to fix it later
 ? Please select a choice:

please help to rectify the situation and explain what is happening

Upvotes: 0

Views: 73

Answers (2)

seddonym
seddonym

Reputation: 17259

South is trying to decide how to create a backwards migration - in other words, how would it roll back your change. If you're happy that you're never going to want to roll back this migration, you can just choose option 3.

If you do want to roll back, then have a look at this post - it explains how to rename a model field (in this case message to message_f).

Upvotes: 2

Eugene Soldatov
Eugene Soldatov

Reputation: 10145

It's normal, you should chose option 2 and enter default value, if you don't plan to use backward migrations it can be any, for example "0". If you further do backward migration, deleted fields will be created anew and they will be filled by this default values.

Upvotes: 1

Related Questions