# Doc's data migration command not working

**URL:** <https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670>\
**Category:** Using the ORM\
**Created:** [August 29, 2022, 8:39am UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670 "2022-08-29T08:39:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shriukan33](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shriukan33/32/9879_2.png) [@Shriukan33](https://forum.djangoproject.com/u/Shriukan33)\
**Post date:** [August 29, 2022, 8:39am UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670/1 "2022-08-29T08:39:08Z")

</div>

Hello,

I’ve been meaning to use the Django’s data migration feature, and the example command ( [url](https://docs.djangoproject.com/en/4.1/topics/migrations/#data-migrations) ) :

```shell
python manage.py makemigrations --empty yourappname

```

I’ve replaced the yourappname with the correct app name I have registered, but then this error is raised :

```auto
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/benja/Documents/GitHub/tn_web/venv/lib/python3.8/site-packages/django/core/management/ __init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/benja/Documents/GitHub/tn_web/venv/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/benja/Documents/GitHub/tn_web/venv/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/benja/Documents/GitHub/tn_web/venv/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/home/benja/Documents/GitHub/tn_web/venv/lib/python3.8/site-packages/django/core/management/base.py", line 98, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/benja/Documents/GitHub/tn_web/venv/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py", line 181, in handle
    changes = {app: [Migration("custom", app)] for app in app_labels}
  File "/home/benja/Documents/GitHub/tn_web/venv/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py", line 181, in <dictcomp>
    changes = {app: [Migration("custom", app)] for app in app_labels}
  File "/home/benja/Documents/GitHub/tn_web/venv/lib/python3.8/site-packages/django/db/migrations/migration.py", line 57, in __init__
    self.operations = list(self. __class__.operations)
AttributeError: type object 'Migration' has no attribute 'operations'

```

It seems to be a bug ? Did I do something wrong here ?

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [August 29, 2022, 9:04am UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670/2 "2022-08-29T09:04:00Z")

</div>

Which version of Django are you using? Is it the latest patch version for the feature version (e.g. 4.0.7 for 4.0)?

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [August 29, 2022, 9:06am UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670/3 "2022-08-29T09:06:47Z")

</div>

Hmm the line of code that’s crashing hasn’t changed in 9 years:

> **[django/django/db/migrations/migration.py at...](https://github.com/django/django/blame/a9e7beb959bc726eab1c192d2625d6ff6cfa70f4/django/db/migrations/migration.py#L56)**
>
> The Web framework for perfectionists with deadlines. - django/django/db/migrations/migration.py at a9e7beb959bc726eab1c192d2625d6ff6cfa70f4 · django/django

Try re-installing Django - perhaps something has modified your copy of Django. Another possibility is that some package you’ve installed is modifying the class in a weird way.

---

<div class="post-metadata">

**Author:** ![Shriukan33](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shriukan33/32/9879_2.png) [@Shriukan33](https://forum.djangoproject.com/u/Shriukan33)\
**Post date:** [August 29, 2022, 9:42am UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670/4 "2022-08-29T09:42:06Z")

</div>

I was using 4.0.4 on my venv, installing 4.0.7 might have fixed it !

No idea what happened, but your solution was spot on, thank you and keep up with the good work !

---

<div class="post-metadata">

**Author:** ![Spha](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/spha/32/9509_2.png) [@Spha](https://forum.djangoproject.com/u/Spha)\
**Post date:** [August 29, 2022, 4:02pm UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670/5 "2022-08-29T16:02:06Z")

</div>

In future you could just delete the db.sqlite3 file and delete older migrations from the migration folder. Then the flush command (python manage.py flush), the db.sqlite3 file will generate itself again - but that would only be if you were comfortable with resetting the database completely

---

<div class="post-metadata">

**Author:** ![Shriukan33](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shriukan33/32/9879_2.png) [@Shriukan33](https://forum.djangoproject.com/u/Shriukan33)\
**Post date:** [August 30, 2022, 11:41am UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670/6 "2022-08-30T11:41:25Z")

</div>

I didn’t mean to erase all my data, the point of a data migration is to act on existing data 🙂  
Also, I’m not using db.sqlite3, but postgres in production. This needs to hit prod as well. Erasing prod db isn’t the solution 🙂

---

<div class="post-metadata">

**Author:** ![Spha](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/spha/32/9509_2.png) [@Spha](https://forum.djangoproject.com/u/Spha)\
**Post date:** [August 30, 2022, 12:11pm UTC](https://forum.djangoproject.com/t/docs-data-migration-command-not-working/15670/7 "2022-08-30T12:11:41Z")

</div>

Ok ignore what I said then. I didn’t know it was in production 👍
