django migration table does not exist
13,118
- drop tables,
- comment-out the model in model.py,
- 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
- comment-in your model in models.py
- go to step 3. BUT this time without --fake
Reference: https://stackoverflow.com/a/27583836/4359237
![varad](https://i.stack.imgur.com/dzokh.jpg?s=256&g=1)
Author by
varad
Updated on June 17, 2022Comments
-
varad about 2 years
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?
-
jozxyqk almost 7 yearsI have just created a new database with no tables. All management commands say 'Table myapp.myapp_mymodel doesn't exist'.. well yeah. The problem was a Form's
forms.ModelChoiceField(queryset=MyModel.staticFunction()
running on module load. Wrapping the static call withlazy(...)
solved it.