-1

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!

user233057
  • 33
  • 5
  • Could you try to run 'python manage.py migrate' with all your migrations and not 'python manage.py makemigrations' ? I suppose that you already have all the migrations and you need to apply them, not create new one. – Oleksandr Dashkov Jan 06 '17 at 10:13
  • @OleksandrDashkov Yes I have tried to run makemigrations with my database succesfully. After I change database in settings.py After I run migrate in new database - the same error. I try to create table in new database as 'report_person' and I get error 'permission denied for relation report_person' It is magic) – user233057 Jan 06 '17 at 10:58
  • Do you have a creation of 'report_person' in your migrations? – Oleksandr Dashkov Jan 06 '17 at 11:19
  • @OleksandrDashkov oh ok. I understand this problem. I have a PersonForm in forms.py after delete it migrations ran succesfully. Text of this form in my answer. And I haven't explicity in this questuon. – user233057 Jan 06 '17 at 12:59

2 Answers2

0

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
Oleksandr Dashkov
  • 2,249
  • 1
  • 15
  • 29
Bijoy
  • 1,131
  • 1
  • 12
  • 23
0

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?)

user233057
  • 33
  • 5
  • because you have a query in the file and not in the class/function. When you run migrations, django execute this file and try to execute this file. Your model doesn't exist yet and you have your exception – Oleksandr Dashkov Jan 06 '17 at 12:59
  • @OleksandrDashkov Aaa. Thank you very much! – user233057 Jan 06 '17 at 13:02