Running makemigrations and migrate, the tables not created in the MySQL database.

File "/home/neptunesharvest/.virtualenvs/neptune-env/lib/python3.7/site-packages/MySQLdb/connections.py", line 226, in query _mysql.connection.query(self, query) django.db.utils.ProgrammingError: (1146, "Table 'neptunesharvest$neptune.deepsea_accessorial' doesn't exist")

This is the error I'm getting, when I run python manage.py makemigrations then migrate, all models are created. But they do not appear in the database. I checked the setting files and everything works. The database still works with the website, it is just not creating the tables! Please help!

Solution:

I figured this out and will post my answer here in case anyone else has this problem: Had to delete all models in the initial migrations file that didn't have a table already associated with them,

[root@cnwbzp3137 migrations]# ls -ltr
total 16
-rw------- 1 root root    0 Mar 28 20:27 __init__.py
-rw-r--r-- 1 root root 5962 Mar 28 20:42 0002_auto_20200328_1242.py
-rw-r--r-- 1 root root  205 Mar 28 20:48 0001_initial.py
drwxr-xr-x 2 root root 4096 Mar 28 20:48 __pycache__

[root@cnwbzp3137 migrations]# rm -rf 0002_auto_20200328_1242.py
 

[root@cnwbzp3137 migrations]# cat 0001_initial.py 
# Generated by Django 3.0.2 on 2020-03-28 12:27

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
    ]
 

then run:

python manage.py migrate --fake-initial
python manage.py makemigrations
python manage.py migrate

https://docs.djangoproject.com/en/2.2/topics/migrations/ Suggestion under 'Adding migrations to apps.' This had nothing to do with pythonanyhwere (all hail), but because I deleted my migrations files while merging a branch.

发布了36 篇原创文章 · 获赞 21 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_39833509/article/details/103977014