No such table: django_site - after dropping db and migrating

I am using django-cookie-cutter.

I've installed it and I'm getting the error: "no such table: django_site"

I have nuked the db (its an sqlite one for now) and done a python migrate and it says "no migrations to perform"

But the site still comes up with the error.

I have django.contrib.sites as an installed app.

Any idea how I can get around this?

Did you do makemigrations before migrate?

Good point! Yeah I did.

I did a python makemigrations again just now.

And got "No changes detected" and then after a migrate it says "no migrations to apply"

I have tried swapping to sqlite (with a new db) and still get the same issue. I'm running in MySQL currently.

I am in the tarpit for the next 5 hrs cause I was trying to do too much at once yesterday - but that should not effect it.

The site works locally - it just isnt working pythonanywhere for some reason.

The error is: MySQLdb._exceptions.ProgrammingError: (1146, "Table 'mooreconsultants$moore.django_site' doesn't exist")

Any ideas?

Maybe drop the database and start over. Be careful what database settings are you running with.

I'm not sure how to drop the DB - I tries to on the MySQL console but I dont have the access.

So I tried to roll back the migration on the "sites" app and then reapply it:

python migrate --fake sites zero
python makemigrations

And I got this error:

django.db.utils.OperationalError: table "django_site" already exists

But the error in the error log is:

django.db.utils.ProgrammingError: (1146, "Table 'mooreconsultants$moore.django_site' doesn't exist")

So the errors are conflicting.

My wsgi file has this line (with the correct password):

os.environ['DATABASE_URL'] = 'mysql://mooreconsultants:<thepassword>$moore'

So it's a conundrum!

Can you remove MySQL? As you can see above I have already done this with the Sqlite db several times before moving to MySQL - so I suspect there is something deeper going on.

Looks like your app and database are in a weird state. You can use MySQL console to clean it and then recreate migrations and migrate.

Ok great.

But I tried to drop the DB and I cant.

And I can select the database but cant drop tables or even list them.

Could I have some assistance on the commands to use please?

What do you see when you run show tables; in your mysql console?

this is what I get:

mysql> show tables;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    314143679
Current database: mooreconsultants$moore
Empty set (12.27 sec)

But of course I cant migrate cause it says the table is there.

That's an entirely different database to the one that you referred to earlier (mooreconsultants$moore vs mooreconsultants$moore.django_site)

I thought that django_site is the table - and mooreconsultants$moore is the db.

Error is: "Table 'mooreconsultants$moore.django_site' doesn't exist"

Can you guys just drop the moore db (I dont have the permissions)? And I'll recreate it and try to migrate again.

Ah. Sorry. I misread it in the post. I have dropped the database for you.

Thanks for that glenn.

I am still having issues.

I have recreated the db 'moore' and then did a python migrate:

python migrate
Operations to perform:
  Apply all migrations: account, admin, auth, contenttypes, money, products, sessions, sites, socialaccount, users
Running migrations:
  No migrations to apply.

So on a fresh db - no migrations to apply?


So I created another Db - moore2 - I made sure I refresh the site in the backend. I did a migrate and the same result:

python migrate
Operations to perform:
  Apply all migrations: account, admin, auth, contenttypes, money, products, sessions, sites, socialaccount, users
Running migrations:
  No migrations to apply.

So on a fresh DB - how can I have no migrations to apply? I thought the records of migrations is kept in the DB.

The site works on my local machine, and also on the clients local machine so something is out of whack on the pythonanywhere hosting.

This is dragging on - any more ideas on what I can do here?

Are you sure you're connecting to the database that you think you're connecting to? Use a shell to check what the DATABASES setting actually is.

Hi Glenn, I'm not quite sure what commands you mean here? Could you direct me to some doco?

Here are my settings:

    'default': {
        'ENGINE': 'django.db.backends.mysql',


os.environ['DATABASE_URL'] = 'mysql://mooreconsultants:<thepassword>$moore'

Now I cant even connect:

django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

Any further ideas?

hmm just to double check- you have the name/user/host setup like this right?

I've gone back to SQLite.

It created a new db - run the migrations - and still the "no django_sites table" error.

So I downloaded the created sqlite db and opened it in a DB Viewer.

The table django_sites is there!

So it's complaining about a table no being present that is actually present?!

So what now? What can be done?

Ok I've managed to fix this by defining the SQLite via an absolute url, rather than the relative one.

Still doesnt explain why I had the same error in MySQL though.

Anyhoo - I have things working for now - even if I am running on SQLite. But it will do for now

Thanks for all your time looking at this thread PythonAnywhere Team!