Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django makemigrations not detecting new model

Tags:

python

django

I used makemigrations earlier in order to make my Django app aware of the tables in my legacy MySql database, and it worked fine. It generated models.py. Now, I want to add a new "UserDetails" model to my app:

class UserDetails(models.Model):
    user = models.CharField(max_length=255)
    telephone = models.CharField(max_length=100)

After saving the file, I ran the following command in the command prompt:

python manage.py makemigrations

But makemigrations is not seeing the new class I wrote inside the models.py, as it always outputs 'No changes detected'

Am I doing it correctly or is there anything wrong with it? I checked my MySQL db and confirmed that no table named UserDetails already exists.

like image 776
logeeks Avatar asked Sep 11 '15 08:09

logeeks


1 Answers

I've met this problem during development and this combination helps me:

python manage.py makemigrations mymodule

This command create migrations for the specific module. It should be in INSTALLED_APPS, but you'll get warning if it's not in there.

python manage.py migrate

Also, mention answer by xiaohen, I've create packages with PyCharm, so I've got init.py file by default.

like image 96
Dracontis Avatar answered Sep 30 '22 19:09

Dracontis