Doc's data migration command not working

Hello,

I’ve been meaning to use the Django’s data migration feature, and the example command ( url ) :

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 :

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 ?

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)?

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

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.

1 Like

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 !

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

I didn’t mean to erase all my data, the point of a data migration is to act on existing data :slight_smile:
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 :slight_smile:

Ok ignore what I said then. I didn’t know it was in production :+1: