Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python manage.py migrate does not make any changes in the postgres database

This seems like a simple problem I am not sure what I am doing wrong. If for example I wanted to add a new field in one of my classes in models.py by changing:

class FeedBack(models.Model):
    feedback = models.CharField(max_length=600)
    user = models.ForeignKey(User,default="")

to

class FeedBack(models.Model):
    feedback = models.CharField(max_length=600)
    email = models.CharField(max_length=100)
    user = models.ForeignKey(User,default="")

then I run

python manage.py makemigrations

python manage.py migrate

and everything seems fine, but no changes have actually been made in the database. When trying to view the feedback table I receive the following exception:

column IngressoMonitor_feedback.email does not exist

also using psql \d+ on the table shows email has not been added

for now I could just use psql to add and alter tables, but I'd prefer to write it in models.py since that seems a lot easier to me.

like image 428
Abendsen Avatar asked Oct 20 '22 06:10

Abendsen


1 Answers

Make sure that the app containing that models.py file is included in INSTALLED_APPS of your project's settings file. In addition, please do not touch the files under the app's migration folder unless you are certain you know what you are doing. Please also make sure that the DB account specified in your settings file have the necessary privileges.

If you recently changed your Django version, this link might be of use to you. But give it a shot anyway and make the migrations per app in this case:

python manage.py makemigrations app_name

If all else fails, just drop the tables of the database, and regenerate everything from scratch. However, if at some point, you messed with any of the migration files, you might want to remove all of them before performing makemigrations to ensure that you have a new and working set of migration files that manage.py can work on.

like image 155
Wannabe Coder Avatar answered Oct 21 '22 23:10

Wannabe Coder