I can't migrate at another database

233 views Asked by At

I have well working project on local. I use postresql. Ok. I create another database in postgres locally and specify new name/user/password in settings.py of project. When I do

$ python manage.py makemigrations

I get error as

relation 'report_person' not exist

And I have tried delete (and not delete) directory 'migrations'. delete pycache. I tried specify Sqlite3 as database - but the same error.

Why I ask? My project don't want to work with another database) I succesfully push project on heroku. Specify parameters in settings.py. Create postgresql. But I can't make migrate on heroku) the same error. I do makemigrations and git commit before push on heroku, but no result Help me please. Thank you Have a nice day!

2

There are 2 answers

1
Bijoy On

try migrating with --fake

python manage.py migrate --fake
python manage.py migrate yourappname --fake

and then again

python manage.py makemigrations
python manage.py migrate
2
user233057 On

Oh, I can't explain this situation. All problems in one little model.

It is from models.py:

from django import models

class Person(models.Model):
    name = models.CharField(max_length=255)
    position = models.CharField(max_length=255)

This part of forms.py (crazy):

from django import form

q = models.Person.objects.all()
qty = range(len(q))
PersonForm = type('PersonForm',
                                (forms.Form,),
                                {'person'+'_'+str(q[i].id): forms.BooleanField(label=q[i].name,
                                        required=False) for i in qty})

And I must before migrations delete this 'PersonForm'. Then migrate will be succesfully in new any database. And after migrations I put this form again. Ok. I don't undestand, why?)