no migrations to apply after deleting a field in models

19 views
Skip to first unread message

amirreza taherkhani

unread,
May 8, 2019, 7:57:54 AM5/8/19
to django...@googlegroups.com
I have this models: 
class Genre(models.Model):
genre = models.CharField(max_length=100)

def __str__(self):
return self.genre


class Book(models.Model):
book_name = models.CharField(max_length=150)
summary = models.TextField(max_length=1000, null=True,blank=True)
author = models.ForeignKey('Author', on_delete=models.CASCADE)
genre = models.ManyToManyField(Genre)
status = [
('a', 'available'),
('b', 'borrowed'),
('r', 'reserved'),
]
book_status = models.CharField(max_length=1, choices=status, default='a')

def __str__(self):
return '{0}({1})'.format(self.book_name, self.author)

def get_absolute_url(self):
return reverse('main_app:book-detail', args=[self.id])


class Author(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
rate = models.IntegerField(default=0)

def __str__(self):
return '{0} {1}'.format(self.first_name,self.last_name)
and i deleted an uuidfield from book table...
then i deleted this file -> 0001_initial.py
and then run : py manage.py makemigrations and migrate
but migrate is not available to recognize the changes :

C:\Users\amir\Documents\GitHub\simple_library> py  manage.py makemigrations
Migrations for 'main_app':
  main_app\migrations\0001_initial.py
    - Create model Author
    - Create model Book
    - Create model Genre
    - Add field genre to book

C:\Users\amir\Documents\GitHub\simple_library> py manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, main_app, sessions
Running migrations:
  No migrations to apply.

what should i do now?

Nelson Varela

unread,
May 8, 2019, 9:06:14 AM5/8/19
to Django users
Don't delete the 0001_initial file!
That is your first state. Just delete the field from you model and do makemigrations again.. You wil get a 0002_ file which deletes the field.


Reply all
Reply to author
Forward
0 new messages