Add new fields on models.py in Django

0

I have the following model in models.py:

class Videos(models.Model):
    title = models.CharField(max_length=45)
    link = models.CharField(unique=True, max_length=45)

    class Meta:
        managed = True
        db_table = 'Videos'

    def __str__(self):
        return '%s' % (self.title)

I want to add two new attributes:

created = models.DateTimeField(default=datetime.now)
number_of_searches = models.PositiveIntegerField(default=0)

The model would look like this:

class Videos(models.Model):
    title = models.CharField(max_length=45)
    link = models.CharField(unique=True, max_length=45)
    created = models.DateTimeField(default=datetime.now)
    number_of_searches = models.PositiveIntegerField(default=0)

    class Meta:
        managed = True
        db_table = 'Videos'

    def __str__(self):
        return '%s' % (self.title)

When I run the python manage.py makemigrations command it tells me there are no changes to apply. When I delete the two lines and return to run the command, he shoots me on the screen:

blog/migrations/0006_auto_20170102_1904.py:
    - Remove field created from videos
    - Remove field number_of_searches from videos

When I add them back he says:

blog/migrations/0007_auto_20170102_1905.py:
    - Add field created to videos
    - Add field number_of_searches to videos

But when I run the python manage.py migrate it shows me the following error:

  

django.db.utils.OperationalError: (1091, "Can not DROP 'created'; check   that column / key exists ")

As if the field existed. I can not find a solution, I would appreciate any help.

    
asked by Genarito 02.01.2017 в 20:07
source

1 answer

0

I have already solved the problem in the following way:

  • Delete the folder (not without first making a backup of it) migrations within the folder of my app.
  • python manage.py makemigrations *miApp*
  • python manage.py migrate *miApp*
  • answered by 17.01.2017 / 16:44
    source