Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django migration table does not exist

I have added new model to my app. I did makemigration and in my migration I can see the code to create my models like:

operations = [
    migrations.CreateModel(
        name='Blog',
        fields=[
            ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
            ('title', models.CharField(max_length=120)),
            ('body', models.TextField()),
            ('post_date', models.DateTimeField(default=django.utils.timezone.now)),
            ('like', models.IntegerField(default=0)),
            ('created_by', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
        ],
        options={
        },
        bases=(models.Model,),

Now when I do python manage.py migrate it gives me error saying table does not exist..

Why I am getting this error. It should have been migrated right ? How to fix this issue?

like image 792
varad Avatar asked Apr 25 '15 05:04

varad


1 Answers

  1. drop tables,
  2. comment-out the model in model.py,
  3. if you are using django version >= 1.7:

python manage.py makemigrations

python manage.py migrate --fake

else

python manage.py schemamigration someapp --auto

python manage.py migrate someapp --fake

  1. comment-in your model in models.py
  2. go to step 3. BUT this time without --fake

Reference: https://stackoverflow.com/a/27583836/4359237

like image 184
sk1pro99 Avatar answered Sep 23 '22 14:09

sk1pro99