Gustux
Gustux

Reputation: 81

Table django_session don't exists when I try use admin with mysql

I'm new with django 1.10 using mysql (5.6.17) (WAMP 2.5) and Python 3.5 under Windows 8.1

I configured fine the mysql connector, I made my models, made makemigrations myapp and migrate myapp, using manage.py terminal with Pycharm.

When I try to acces in admin web page, I have this message (trabajo is my app inside my project: programa)

Exception Value:

(1146, "Table 'programa.django_session' doesn't exist")

In my settings.py file have:

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

The apps block:

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

To connect the database:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME' : 'programa',
        'USER' : 'myownuser',
        'PASSWORD' : 'myownpassword',
        'HOST' : '',
        'PORT' : '',
    }
}

Why have this error in the admin page? What can I do to solve this?

Thanks in advance. Any help is welcome!! ;-)

Gustavo.

Upvotes: 7

Views: 17553

Answers (4)

Natnael A.
Natnael A.

Reputation: 628

I ran into the same problem, my issue was that migration history had recorded that it had successfully created a table for session even though it hadn't actually done so on my MySQL DB.

I was able to fix it by running command:

python manage.py migrate --fake sessions zero

Then:

python manage.py migrate sessions

Upvotes: 3

amJayem
amJayem

Reputation: 57

I got this error:

File "C:\Python39\lib\site-packages\MySQLdb\connections.py", line 259, in query_mysql.connection.query(self, query) MySQLdb._exceptions.ProgrammingError: (1146, "Table
'database_name.django_session' doesn't exist")

and solved by the following command:

python manage.py migrate sessions

Upvotes: 2

Sarita Ishwarkar
Sarita Ishwarkar

Reputation: 129

Run command:

python manage.py migrate sessions

Upvotes: 8

Chris Curvey
Chris Curvey

Reputation: 10389

if all you did was "migrate myapp", then you only created the tables for your app. I think a plain "migrate" will create all the tables for Django and it's contributed modules.

Upvotes: 10

Related Questions