0

I have django running on ubuntu, and I am trying to set it up with mysql as db. I followed these (1, 2, 3) guides, but when I run python manage.py migrate --run-syncdb I get the error django.db.utils.OperationalError: (1050, "Table 'myapp_mymodel' already exists"). How do I fix this (I am using MySQL version 5.7.41, Ubuntu 18.04, Python 3.6, Django 3.2)?

migrations:

admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
 [X] 0012_alter_user_first_name_max_length
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
myapp
 [ ] 0001_initial
 [ ] 0002_alter_user_uid
sessions
 [ ] 0001_initial
Randusr
  • 39
  • 6
  • Did you populate your DB from a backup/script or have you just run migrations? Can you add the output you get from running `python manage.py showmigrations` to your question? – Iain Shelvington Feb 18 '23 at 16:31
  • @IainShelvington I just ran migrations, no backup/script. Also, I have now added the output from showmigrations. – Randusr Feb 18 '23 at 16:58
  • Unfortunately MySQL does not support transactions for schema changes so when a migration fails (as seems to be the case here) you'll need to undo the changes manually. Luckily it's the initial migration so you can just delete all tables for that app - delete all the tables with the prefix `myapp_` in the DB – Iain Shelvington Feb 18 '23 at 17:06
  • so do I delete, migrate, then add and repeat? – Randusr Feb 18 '23 at 17:08
  • Delete all the tables prefixed with `myapp_` then run migrate again, you shouldn't get the table already exists error – Iain Shelvington Feb 18 '23 at 17:09
  • @IainShelvington I did that, but now I am getting the error ```django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'uuid' used in key specification without a key length")```. uuid is ```models.TextField(default=uuid.uuid4, editable=False)```, and it used to be unique=True, but I set unique to False now. – Randusr Feb 18 '23 at 17:34

0 Answers0