search

Home  >  Q&A  >  body text

python - django models.py增加后MySQL数据库中并没有生成相应的表

PHPzPHPz2895 days ago441

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 09:36:32

    First you need to check your settings.py configuration, where:

    # settings.py
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'OPTIONS': {
                'read_default_file': '/path/to/my.cnf',
            },
        }
    }
    # my.cnf
    [client]
    database = NAME
    user = USER
    password = PASSWORD
    default-character-set = utf8

    If your configuration is not mysql, Django will use sqlite by default, and when you run the above command, a sqlite database file will be generated in the project directory.

    If the configuration is correct and it is mysql, after running your script, the corresponding table will be generated in the corresponding mysql database. The default table name is <app_name>_<model_name>

    If you still have questions, please refer to:
    https://docs.djangoproject.co...

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:36:32

    There are several situations when this situation occurs:
    1. The db configuration in django settings.py is incorrect
    2. There may be a problem with the db model writing
    There may be other situations

    A little suggestion: Show the results of executing the python manage.py migrate command, so that others can help you quickly analyze, locate and solve the problem.

    reply
    0
  • Cancelreply