7

I have the follow project structure:

MyProject
|--myBaseApp
|  |--migrations
|  |--__init__.py
|  |--models.py
|  |...
|--myClientApp
|  |--migrations
|  |--__init__.py
|  |--models.py
|  |...
|--myProject
|  |--__init__.py
|  |--settings.py
|  |--urls.py
|  |...
|--manage.py
|...

I can import to myClientApp/models.py the models.py from myBaseApp, but when I use the commands on terminal mode:

python manage.py makemigrations
python manage.py migrate myClienteApp

The Django creates, on data base, all tables from models.py, both myClienApp/models.py and myBaseApp/models.py. I'd like to make migrate only the models.py from myClienApp/models.py. It's possible? Or do I need to create other project?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Marcelo Pereira
  • 133
  • 1
  • 2
  • 5

3 Answers3

3

If you want to make migrations only within one app use,

python manage.py makemigrations <app_name>

If you want to run migrations only within one app use,

python manage.py migrate <app_name>
Achala Dissanayake
  • 810
  • 3
  • 16
  • 33
0

It sounds like this is the first migration -- Django will migrate the stuff from the myBaseApp if so

You can try to run a specific migration instead i.e.:

./manage.py migrate myapp 0005_migration_to_run

  • It's actually sufficient to only use the migration *number* when targeting a specific migration, e.g. `./manage.py migrate myapp 0005`. Information on the subject: https://docs.djangoproject.com/en/4.1/topics/migrations/#reversing-migrations – kunambi Dec 03 '22 at 12:35
0

In addition to other answers, you can make migrations for multiple specific apps by specifying them as shown below:

python manage.py makemigrations app1 app2

And, 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'.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129