user974685
user974685

Reputation: 23

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

In mysite.settings.py I have:

   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. I tried two things for NAME as you can see.

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.

Any advice on how to find the problem? How to get an error message?

Thank you

Upvotes: 0

Views: 457

Answers (1)

k33da_the_bug
k33da_the_bug

Reputation: 820

DATABASES property specifies your DB configurations. Now NAME is the property which specifies your database 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. 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.

(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.

Upvotes: 1

Related Questions