Loading... 官方文档片段:[https://docs.djangoproject.com/en/2.0/topics/install/#get-your-database-running](https://docs.djangoproject.com/en/2.0/topics/install/#get-your-database-running) 运行环境 + Python3.7 + Django2.2.6 + Mysql5.7 1. 下载mysqlclient ```python pip install mysqlclient ``` 2. 修改setting.py的配置 ```python DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'demo04', 'USER': 'root', 'PASSWORD': 'root', 'HOST': 'localhost', 'PORT': 3306, } } ``` 3. 执行迁移命令吧 ```python python manage.py makemigrations python manage.py migrate ``` # django.dgrammingError: (1146, u"Table'' doesn't exist") 参考文章:https://stackoverflow.com/questions/27583744/django-table-doesnt-exist ```python python manage.py makemigrations python manage.py migrate --fake 注释掉模型 python manage.py makemigrations python manage.py migrate ``` # Django | 模型类变更后生成迁移文件,报错:You are trying to add a non-nullable field 'BookName' to BookInfo without a default.... 报错: You are trying to add a non-nullable field 'BookName' to BookInfo without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 1. Provide a one-off default now (will be set on all existing rows) 2. Quit, and let me add a default in [models.py](http://models.py) 原因: 在模型类中添加了一个非空字段,而该模型类对应的表中,已经存在数据,而这些现存的数据并没有新增字段的值 # you are trying to add a non-nulllable field xxx to xxx without a default > 新增字段时报错,具体的意思,就是说该字段为非空字段,在字段出添加`null=True` # django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syn tax to use near 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED' at line 1") > 在生成迁移文件时`python manage.py makemigrations`,报错:django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syn tax to use near 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED' at line 1") 运行环境 - CentOS:6.5 - MySQL:5.1 - Django:2.1.1 - Python:3.7 ```python DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'autotest', 'USER': 'root', 'PASSWORD': '123456', 'HOST': '127.0.0.1', 'PORT': '3306', 'OPTIONS': {'isolation_level': None} # 加这句 } } ``` - 如果修改完,不起作用,那就是mysql版本太低了,不支持mysql5.5版本 Last modification:August 29th, 2020 at 06:13 am © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 ×Close Appreciate the author Sweeping payments Pay by AliPay Pay by WeChat