Mike Me
Mike Me

Reputation: 2392

Error when running migrate command Django

I am trying to deploy my first web project on a server. I am getting this error when running migrate and makemigrations:

ProgrammingError (1146, "Table '<user>$<dbname>.<table_name>'' doesn't exist")

Everywhere it says that you should run manage.py syncdb but this is obsolete , also when running manage.py --run-syncdb the same error is given.

models

class Book(models.Model):

    name = models.CharField(max_length=350)
    author = models.CharField(max_length=350)
    category = models.CharField(max_length=200)

    def __str__(self):
        return self.name

snipppets from settings

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '<your_username>$<your_database_name>',
        'USER': '<your_username>',
        'PASSWORD': '<your_mysql_password>',
        'HOST': '<your_mysql_hostname>',
    }
} #Everything is replaced with the correct credentials

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main_app',
    'accounts',
]

The DB is empty on the server. On my PC (when I developed it locally) it worked, it created the table for me when it didn't exist in the DB.

I am using Django 1.11 and Mysql 5.6.27.

I tried other answers but did not help me. Can you please suggests what can I do to solve this issue?

Upvotes: 0

Views: 733

Answers (2)

Farzan Ahmadi
Farzan Ahmadi

Reputation: 43

You don't need to use syncdb.
for the first time you creating your Django project in order to creating pre-installed apps (such as admin interface) database in django you need to use :
python manage.py migrate

it creates all necessary database tables and relations.
but every time you make changes to your app like creating new columns in your models, you can use:
python manage.py makemigrations [your app name]
the result will be something like below :
(env35) someone@shell:~/bookstore$ python manage.py makemigrations books Migrations for 'books': 0005_publisher_family.py: - Add field family to publisher
and finally you run:

python manage.py migrate

to Synchronizes the database state with the current set of models and migrations.

Upvotes: 0

bluszcz
bluszcz

Reputation: 4128

You should use migrations mechanism: https://docs.djangoproject.com/en/1.11/topics/migrations/

./manage.py makemigrations # this creates migrations files
./manage.py migrate # this applies migrations

Upvotes: 2

Related Questions