Forums

django_session' doesn't exist"

Hello, i am facing this error: 1146, "Table 'xx$xx.django_session' doesn't exist".

I've tried many solutions bot none worked! migrate makemigrations syncdb

all migrations were done: No migrations to apply.

Could you give us the exact output that you get when you run makemigrations?

.

python manage.py migrate --fake

System check identified some issues:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warni
ngs into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: accounts, admin, auth, contenttypes, groups, posts, sessions
Running migrations:
  Applying posts.0001_initial... FAKED

------------------------------
(djan111) 19:20 ~/mhssocial (master)$ python manage.py migrate
System check identified some issues:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warni
ngs into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: accounts, admin, auth, contenttypes, groups, posts, sessions
Running migrations:
  No migrations to apply.
(djan111) 19:21 ~/mhssocial (master)$ python manage.py makemigrations
No changes detected

İ had some duplicate tables, thats why i used FAKE. Thanks in advance!

[edit by admin: formatting]

OK, that's the results for migrate -- but what about makemigrations?

[edit] Oops, sorry, didn't read to the bottom of your post. Will answer again with some more ideas.

Hmm, the "duplicate tables" thing worries me a bit. What errors did you get before regarding them?

.

(djan111) 19:11 ~/mhssocial (master)$ python manage.py migrate
        System check identified some issues:
        WARNINGS:
        ?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
                HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https
        ://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
        Operations to perform:
          Apply all migrations: accounts, admin, auth, contenttypes, groups, posts, sessions
        Running migrations:
          Applying posts.0001_initial...Traceback (most recent call last):
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/django/db/backends/utils.py", line 62, in execute
            return self.cursor.execute(sql)
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 101, in execute
            return self.cursor.execute(query, args)
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
            self.errorhandler(self, exc, value)
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
            raise errorvalue
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
            res = self._query(query)
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
            rowcount = self._do_query(q)
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
            db.query(q)
          File "/home/mhsozmen/.virtualenvs/djan111/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
            _mysql.connection.query(self, query)
        _mysql_exceptions.OperationalError: (1050, "Table 'posts_post' already exists")

and after doing it with FAKE:

(djan111) 19:17 ~/mhssocial (master)$ python manage.py migrate --fake
System check identified some issues:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https
://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: accounts, admin, auth, contenttypes, groups, posts, sessions
Running migrations:
  Applying posts.0001_initial... FAKED
  Applying sessions.0001_initial... FAKED
(djan111) 19:18 ~/mhssocial (master)$ python manage.py makemigrations                                                                                                                                            
Migrations for 'posts':
  posts/migrations/0002_auto_20180807_1918.py
    - Alter field message on post
(djan111) 19:18 ~/mhssocial (master)$ python manage.py makemigrations
No changes detected

Feel free to access my files if you have the accessibility to do!

Thanks.

OK, so when you ran the migration initially, it failed because there was a table already there called posts_posts. This meant that it didn't run the migrations that should have been done at the same time, which includes creating the "sessions" table. When you ran the fake migration, you essentially told Django that you didn't want it to ever do any of the migrations from the failed run -- which includes creating the sessions table. So whatever happens in the future, it won't create it because it thinks you were deliberately telling it not to create it.

Do you have any important data in the database? Because the simplest way to fix all of this would be to delete everything and start again from scratch.

No, i don't have important data. Should i erase all the data or just the database part?

Thanks for your fast response :)

You should just need to erase the database, I think the migrations are OK. So, start a MySQL console on the database you want to delete, then run

DROP DATABASE mhsozmen$databasename;

...replacing databasename with the name you specified when you created it.

Next, create the database again from the "Databases" page, and then run

python manage.py migrate

....once more. Hopefully it will work this time :-)

I erased the database and faced some migrations errors, fixed them and now everything works!

Thank you :)

great to hear!