0

I write some models in my project, then i deleted an uuid field from my book model and the deleted the 0001_initial.py file and run make migrations and migrate

but when i run py manage.py migrate, show me this message:

  • No migrations to apply.

and when run 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

this are my 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')
    isbn        = models.CharField(max_length=13,
                            help_text='read '
            '<a href="https://www.isbn-international.org/content/what-isbn">'
                                      'here'
                                      '</a>'
                                      ' to help ')

    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)
2
  • 2
    I'm not sure if I can help with this - but I'm really not sure why you deleted just the first migration. When you get into db/migration trouble like this, my recommendation would be to delete ALL migrations, then run makemigrations again (followed by migrate of course) Commented May 8, 2019 at 10:29
  • If you delete the migrations, you also need to drop the database. But don't delete the migrations. Commented May 8, 2019 at 12:05

1 Answer 1

0

Delete the entry of the migration you deleted from table django_migrations as well.

Sign up to request clarification or add additional context in comments.

2 Comments

I will try nuking the whole shebang by adding this to my script: psql -c 'delete from django_migrations'
The script drops the entire database, including that table, so no change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.