# Makemigrations is not making all migrations

**URL:** <https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881>\
**Category:** Using the ORM\
**Created:** [November 8, 2022, 6:01am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881 "2022-11-08T06:01:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 8, 2022, 6:01am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/1 "2022-11-08T06:01:14Z")

</div>

I have several apps inside a project:

Post  
Poll  
Users

I have deleted all tables in the database. I have deleted all migration files and I have deleted all **pycache** directories inside the app folders.

When I run makemigrations only ONE model (Post) migration file gets created and I have to manually go and create the other migration files using makemigrations modelname.

Why is this happening please?

---

<div class="post-metadata">

**Author:** ![Fikralaksana](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fikralaksana/32/9792_2.png) [@Fikralaksana](https://forum.djangoproject.com/u/Fikralaksana)\
**Post date:** [November 8, 2022, 8:23am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/2 "2022-11-08T08:23:59Z")

</div>

it happend because you dalete migrations folder and \_\_init\_\_.py inside it.  
I don’t really know the exact detail, but I think django need that folder internally to create migrations file.

if you want to **reset** the migrations, just delete file inside migrations folder that have number on the beginning of file name (ex: `0001_initial.py` , etc). and delete all data in your table.

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 8, 2022, 8:26am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/3 "2022-11-08T08:26:30Z")

</div>

Yeah I did not delete the migrations folder. I only deleted the files inside it (not **init**.py) and I deleted the **pycache** directories

---

<div class="post-metadata">

**Author:** ![Fikralaksana](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fikralaksana/32/9792_2.png) [@Fikralaksana](https://forum.djangoproject.com/u/Fikralaksana)\
**Post date:** [November 8, 2022, 8:41am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/4 "2022-11-08T08:41:59Z")

</div>

sorry there, should be asking first. 😀  
did you already delete the table?  
if you using sqlite3, try deleting the file

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 8, 2022, 8:43am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/5 "2022-11-08T08:43:17Z")

</div>

> [@calcanisa](#):
>
> I have deleted all tables in the database. I have deleted all migration files and I have deleted all **pycache** directories inside the app folders.

As in my original post

---

<div class="post-metadata">

**Author:** ![Fikralaksana](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fikralaksana/32/9792_2.png) [@Fikralaksana](https://forum.djangoproject.com/u/Fikralaksana)\
**Post date:** [November 8, 2022, 8:59am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/6 "2022-11-08T08:59:16Z")

</div>

I can’t reproduce this issue.

I already deleting all migrations file that has file name started with number.  
Then deleting my sqlite3 file.  
Then I run `python manage.py makemigrations`.  
Then all app successfully creating migrations file.

> Usually this issue happend when migrations folder deleted in app.

maybe you can add more details (step by step) how you try to reset migrations and finally got that issue.

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 8, 2022, 11:14am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/7 "2022-11-08T11:14:21Z")

</div>

The steps are exactly as I put it there not sure what else to tell you. I am not using sqlite but mysql

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 8, 2022, 1:07pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/8 "2022-11-08T13:07:35Z")

</div>

If you’ve deleted _all_ tables, including Django’s “internal” tables, I’d suggest running `migrate` first. That should create the initial set of tables needed by Django to function. Then you can try running `makemigrations` again.

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 8, 2022, 1:09pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/9 "2022-11-08T13:09:59Z")

</div>

Thank you Ken I did not think about doing that. I know you must run migrate when you start a project, but I did not think in doing it with this. Again thank you

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 9, 2022, 7:43am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/10 "2022-11-09T07:43:02Z")

</div>

I did what you suggested and after deleting the database and all existing migration files I ran migrate and got an error

Here is the traceback:

```auto
Operations to perform:
  Apply all migrations: admin, auth, authtoken, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying admin.0001_initial...Traceback (most recent call last):
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 75, in execute
    return self.cursor.execute(query, args)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb.OperationalError: (1824, "Failed to open the referenced table 'users'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/core/management/ __init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/core/management/ __init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/core/management/base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 349, in handle
    post_migrate_state = executor.migrate(
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/migrations/executor.py", line 255, in apply_migration
    migration_recorded = True
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 164, in __exit__
    self.execute(sql)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 199, in execute
    cursor.execute(sql, params)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/utils.py", line 103, in execute
    return super().execute(sql, params)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 75, in execute
    return self.cursor.execute(query, args)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/home/calvin/.local/share/virtualenvs/website-OCaWupbT/lib/python3.8/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1824, "Failed to open the referenced table 'users'")
```

If I create the migration files manually then it works. How do I fix this pls?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 9, 2022, 1:01pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/11 "2022-11-09T13:01:21Z")

</div>

That looks like you might have dropped one of the database system tables.

At this point, I’d suggest you drop the database and recreate it.

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 9, 2022, 1:07pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/12 "2022-11-09T13:07:18Z")

</div>

Hi Ken

How is it possible for me to drop system tables when I empty the database? Any case I deleted the database and recreated it and the same error. It is not creating the migrations files.

The problem is with my user model, because if I do python manage.py makemigrations users first and then I run migrate then everything works fine.

Sorry no it does not create my other models’ migration files either. Just the systems tables and the users table.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 9, 2022, 1:26pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/13 "2022-11-09T13:26:04Z")

</div>

Please describe in detail your project directory layout. (Just the directories, I don’t need to see all the individual files.)

Identify what versions of Python and Django you are using.

Also post the INSTALLED\_APPS section of your settings file.

Finally, examine your source code files to identify if you have _any_ database-related operations (queries, inserts, etc) at the “module” layer of a file. (Meaning that that code is not in a function.)

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 9, 2022, 2:20pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/14 "2022-11-09T14:20:31Z")

</div>

Ok my dir layout is as follows:

backend (containing folder)  
/ cooking (project folder)  
/ api (app)  
/ pages (app)  
/ posts (app)  
/ storage (static files)  
/ users (app)  
/ usersettings (app)

```auto
INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",

    # THIRD PARTY APPS
    "rest_framework",
    "rest_framework.authtoken",
    "drf_yasg",
    "corsheaders",
    
    # CUSTOM APPS
    "api",
    "users",
    "posts",
    "usersettings",
]
```

Using:

Python 3.8  
Django 4.1

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 9, 2022, 3:11pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/15 "2022-11-09T15:11:32Z")

</div>

When you deleted the files from the `migrations` directory, did you also delete the ` __init__.py` files? If so, you’ll need them in there. (They can be empty files (0 length) but they must exist.)

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [November 9, 2022, 5:06pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/16 "2022-11-09T17:06:28Z")

</div>

After a struggle I finally figured it out. Because I have a custom user model I cannot just run migrate. I must first make a migration for my custom user model and then I can run migrate.

Thanks for the help

---

<div class="post-metadata">

**Author:** ![aguerolas](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aguerolas/32/11715_2.png) [@aguerolas](https://forum.djangoproject.com/u/aguerolas)\
**Post date:** [January 12, 2023, 6:26am UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/17 "2023-01-12T06:26:53Z")

</div>

i just got the same problem and i can`t figured it out. what do u mean when you`re saying first make a migration for my custom user model and then I can run migrate. please, i need help

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 12, 2023, 12:20pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/18 "2023-01-12T12:20:37Z")

</div>

If you’re having an issue with migrations, you’ll be better off if you open up a new topic with the specifics regarding your particular situation. In your description, please include the exact command(s) you are running and the complete responses you are receiving.

---

<div class="post-metadata">

**Author:** ![calcanisa](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calcanisa/32/10066_2.png) [@calcanisa](https://forum.djangoproject.com/u/calcanisa)\
**Post date:** [January 12, 2023, 12:33pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/19 "2023-01-12T12:33:40Z")

</div>

I have a custom user model and if I don’t run the migration for users first then the other migrations fail because most of the other models depend on user. Hope it helps

---

<div class="post-metadata">

**Author:** ![buswedg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/buswedg/32/3229_2.png) [@buswedg](https://forum.djangoproject.com/u/buswedg)\
**Post date:** [January 14, 2023, 8:26pm UTC](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881/20 "2023-01-14T20:26:32Z")

</div>

Just as a handy hint for the OP. If you want to delete all your migrations in the future, but not the ` __init__.py`’s, then use a variation of:

```auto
find . -path "*/migrations/*.py" -not -name " __init__.py" -delete && find . -path "*/migrations/*.pyc" -delete

```

[Next page](https://forum.djangoproject.com/t/makemigrations-is-not-making-all-migrations/16881.md?page=2)
