PyCharm 中使用 Django 無法創建 MySQL 數據表:為什么我的數據表沒有生成?

PyCharm 中使用 Django 無法創建 MySQL 數據表:為什么我的數據表沒有生成?

pycharm 中使用 django 無法成功創建 mysql 數據表

pycharm 中使用 django 連接 mysql 數據庫后,在執行“python3 manage.py makemigrations”命令后卻發現 mysql 數據表沒有創建成功。

系統環境:

  • windows 10
  • python 3.8.6
  • django 3.2.19
  • mysqlclient 2.1.1
  • mysql 0.0.3

項目配置:

  • models.py 中定義了模型
  • settings.py 中注冊了 app 并配置數據庫信息

問題現象:

  • 運行“python3 manage.py makemigrations”和“python3 manage.py migrate”命令后,mysql 中沒有創建數據表。

解決方法:

經過仔細檢查,發現該問題是由 python 3 的版本沖突引起的。在 windows 環境中,使用“python3”命令可能會執行 windows 自帶的 python 3,而不是安裝的 python 3.8.6。因此,需要明確指定 python 解釋器:

python manage.py makemigrations python manage.py migrate

提示:

  • 運行“python”命令,如果打開的是 windows 應用商店,則說明當前環境使用的 python 3 是 windows 自帶的。
  • 正確安裝的 python 3 應該可以通過直接運行“python”命令進入。

? 版權聲明
THE END
喜歡就支持一下吧
點贊14 分享