You have 2 unapplied migration(s). Your project ma...

Criado em: 23 de abril de 2025

Respondido usando O3 por Chat01

Pergunta

You have 2 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): api, users.
Run 'python manage.py migrate' to apply them.
April 23, 2025 - 11:07:04
Django version 4.2.15, using settings 'config.settings.development'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

(doccano-py3.9) C:\Users\justm\OneDrive\Ambiente de Trabalho\LES\doccano-master\doccano-LES\backend>python manage.py migrate
System check identified some issues:

WARNINGS:
?: (staticfiles.W004) The directory 'C:\Users\justm\OneDrive\Ambiente de Trabalho\LES\doccano-master\doccano-LES\backend\client/dist/static' in the STATICFILES_DIRS setting does not exist.
Traceback (most recent call last):
File "C:\Users\justm\OneDrive\Ambiente de Trabalho\LES\doccano-master\doccano-LES\backend\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\justm\AppData\Local\pypoetry\Cache\virtualenvs\doccano-OF2EpuCr-py3.9\lib\site-packages\django\core\management_init_.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\justm\AppData\Local\pypoetry\Cache\virtualenvs\doccano-OF2EpuCr-py3.9\lib\site-packages\django\core\management_init_.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\justm\AppData\Local\pypoetry\Cache\virtualenvs\doccano-OF2EpuCr-py3.9\lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\justm\AppData\Local\pypoetry\Cache\virtualenvs\doccano-OF2EpuCr-py3.9\lib\site-packages\django\core\management\base.py", line 458, in execute
output = self.handle(*args, **options)
File "C:\Users\justm\AppData\Local\pypoetry\Cache\virtualenvs\doccano-OF2EpuCr-py3.9\lib\site-packages\django\core\management\base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
File "C:\Users\justm\AppData\Local\pypoetry\Cache\virtualenvs\doccano-OF2EpuCr-py3.9\lib\site-packages\django\core\management\commands\migrate.py", line 120, in handle
executor.loader.check_consistent_history(connection)
File "C:\Users\justm\AppData\Local\pypoetry\Cache\virtualenvs\doccano-OF2EpuCr-py3.9\lib\site-packages\django\db\migrations\loader.py", line 327, in check_consistent_history
raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration api.0001_initial is applied before its dependency users.0001_initial on database 'default'.

(doccano-py3.9) C:\Users\justm\OneDrive\Ambiente de Trabalho\LES\doccano-master\doccano-LES\backend>

Pensamento

Troubleshooting Django migration error

It looks like the error is caused by a migration dependency issue. InconsistentMigrationHistory happens when migrations are applied in the wrong order or dependencies are missing. To fix this, try resetting the migration history and adjusting the order. Running python manage.py migrate --fake might help mark migrations as applied without actually running them. You can also reverse and reapply migrations to ensure the correct order and dependencies.

Thought for 10 seconds

Resposta

What went wrong

Django keeps a record of every migration it has run in the django_migrations table.
When you see

Migration api.0001_initial is applied before its dependency users.0001_initial

it means:

  • The database already thinks api 0001 ran ✔️
  • But the migration it depends onusers 0001 – is missing from the history ✖️

That breaks Django’s “all dependencies must be satisfied” rule, so it stops.


3 common ways to fix it

SituationQuick recipeWhat it does
You’re on a throw-away/dev database and don’t care about its data```bash

Stop the server first

python manage.py flush # or drop/re-create the DB file/schema python manage.py migrate

text
| **You need to keep the existing data** and are confident the missing migration’s operations are already reflected in the DB (often true for “initial” migrations) | ```bash python manage.py migrate users 0001 --fake # or --fake-initial ``` | Adds a row to `django_migrations` saying “users 0001 ran” without touching the tables. | | **You want to be 100 % safe** (e.g. production) and are not sure if the missing migration actually ran | ```bash python manage.py migrate api 0001 zero # unapply python manage.py migrate users # apply the dependency python manage.py migrate api # re-apply in order ``` | Rolls back `api 0001`, applies the dependency for real, then reapplies `api 0001`. | > **Tip:** run `python manage.py showmigrations` first so you can see exactly what Django thinks is applied. --- ### Why did this happen? * Someone may have used `--fake` earlier, applied migrations in a different branch, or manually edited the DB. * Copying a pre-populated DB file without its full migration history is another common cause. --- ### About the static-files warning

(staticfiles.W004) The directory ...\client\dist\static does not exist.

text
That path is listed in `STATICFILES_DIRS`, but the build step that creates the front-end assets (e.g. `npm run build`) hasn’t been run yet. Until you actually build the front-end—or remove the entry—you can ignore the warning. --- ### Next steps 1. Pick the repair method that fits your environment. 2. Re-run `python manage.py migrate`. 3. Verify with `showmigrations` that everything is marked as applied in order. 4. (Optional) run your front-end build so the static directory exists, or remove the setting while developing. That should get your Django server running cleanly again. If anything’s unclear, let me know what you see after trying the fix and I’ll help you dig deeper!

Compartilhar esta Q&A