简体   繁体   English

按照 Django 教程,“python manage.py migrate”不会创建任何 Django 表(MySQL、Pycharm)

[英]Following Django tutorial, "python manage.py migrate" doesn't create any django tables (MySQL, Pycharm)

In mysite.settings.py I have:在 mysite.settings.py 我有:

   DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.path.join(BASE_DIR, 'test'),
        #'NAME': 'test',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '3306',
    }}

When I run 'python manage.py migrate' in the PyCharm terminal, nothing happens, no error message etc. No new tables are created in the database specified.当我在 PyCharm 终端中运行 'python manage.py migrate' 时,没有任何反应,没有错误消息等。没有在指定的数据库中创建新表。 I tried two things for NAME as you can see.如您所见,我为 NAME 尝试了两件事。

MySQL Server version 8.0.19 MySQL Connector/Python 8.0.19 Python version 3.8 In PyCharm I have package mysqlclient 1.4.6 installed. MySQL 服务器版本 8.0.19 MySQL 连接器/Python 8.0.19 Python 版本 3.8 在 PyCharm 我安装了包 mysqlclient 1.4.6。

Any advice on how to find the problem?关于如何找到问题的任何建议? How to get an error message?如何获取错误信息?

Thank you谢谢

DATABASES property specifies your DB configurations. DATABASES属性指定您的数据库配置。 Now NAME is the property which specifies your database name.现在NAME是指定您的数据库名称的属性。

Currently here 'NAME': os.path.join(BASE_DIR, 'test'), won't work as it will give you something like C:/YourUser/YourPath... so this string is not a valid db name.目前这里'NAME': os.path.join(BASE_DIR, 'test'),不会工作,因为它会给你类似C:/YourUser/YourPath...所以这个字符串不是一个有效的数据库名称。 basically (os.path.join() returns a path to your project directory)

First create a db manually on MySql, note the name and put it in property as 'Name': DBNAME in SETTINGS.py .首先在 MySql 上手动创建一个数据库,记下名称并将其作为'Name': DBNAME in SETTINGS.py放在属性中。

(Make sure you have your environment set while running following commands) Then try python manage.py makemigrations for checking migration changes, if everything goes fine up till here then fire python manage.py migrate command. (确保在运行以下命令时设置了环境)然后尝试使用python manage.py makemigrations来检查迁移更改,如果到这里一切正常,则启动python manage.py migrate命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM