Reputation: 12034
I'm using Django and I have an schema like this:
mainapp
|---mainapp
| |---migrations.py
| |---models/
|---app2
|---migrations/
|---models/
But, when I execute:
python manage.py migrate
it is generationg the tables of mainapp/models
, but no the app2/models
and app2/migrations
either.
How can execute those migrations?
Upvotes: 6
Views: 13004
Reputation: 1
First to INSTALLED_APPS in settings.py
, you need to set all apps which you want to make migrations and migrate for as shown below:
# "settings.py"
INSTALLED_APPS = [
'app1',
'app2'
]
Then, run the command below which can make migrations for all apps set in INSTALLED_APPS
in settings.py
:
python manage.py makemigrations
Then, run the command below which can migrate for all apps set in INSTALLED_APPS
in settings.py
:
python manage.py migrate
In addition, you can make migrations for specific multiple apps by specifying them as shown below:
python manage.py makemigrations app1 app2
But, if you specify the apps which are not set in INSTALLED_APPS
in settings.py
as shown below:
python manage.py makemigrations app1 app2 app3 app4
Then, there are the errors below so no migrations are made for all the specified apps:
No installed app with label 'app4'.
No installed app with label 'app3'.
In addition, you can migrate for only one specific app by specifying it as shown below:
python manage.py migrate app1
But, you cannot migrate for multiple specific apps by specifying them as shown below:
python manage.py migrate app1 app2
Then, there is the error below:
CommandError: Cannot find a migration matching 'app2' from app 'app1'.
Upvotes: 1
Reputation: 3827
Make sure you have added the app in the installed apps.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mainapp',
'app2',
#......,
#......,
]
Then create migrations
using python mananage.py makemigrations
and migrate with python manange.py migrate
Upvotes: 3
Reputation: 27513
first of all try
python manage.py makemigrations
for a specific app
python manage.py makemigrations appname
this will migrate all the apps
then
python manage.py migrate
hope it helps
Upvotes: 9