Jam1 Jam1 - 3 months ago 149
MySQL Question

Django not creating tables " Table django_session does not exist"

Whenever I run

python manage.py migrate
I cannot get the required tables. The only tables that I get are
django_content_type
and
django_migrations
. Because of this I cannot log into the admin page or create a super user. I am using
MySQL-connector-python-rf
, python 3.4 and Django 1.9.8 I have followed instructions of deleting the tables to creating a new database and the problem still persist.

This is my database and apps setup in
settings.py


# Application definition

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

'usermie',
]

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.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'testerdb',
'USER': 'root',
'PASSWORD': '',
}
}


I was using django before and working on a project on this same computer, but now I do not know what has happened and why I am not getting the tables.

Below is what I get when I run
python manage.py migrate


(mie) C:\Users\dane_\DjangoProjects\pagemie>python manage.py makemigrations
Migrations for 'usermie':
0001_initial.py:
- Create model Usermie

(mie) C:\Users\dane_\DjangoProjects\pagemie>python manage.py migrate
Operations to perform:
Apply all migrations: contenttypes, auth, sessions, admin, usermie
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 177, in _execute_wrapper
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\cursor.py", line 515, in execute
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 488, in cmd_query
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 395, in _handle_result
mysql.connector.errors.ProgrammingError: 1050 (42S01): Table 'django_content_type' already exists
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\migrations\operations\models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\base\schema.py", line 284, in create_model
self.execute(sql, params or None)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\base\schema.py", line 110, in execute
cursor.execute(sql, params)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 227, in execute
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 180, in _execute_wrapper
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\base.py", line 177, in _execute_wrapper
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\cursor.py", line 515, in execute
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 488, in cmd_query
File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\connection.py", line 395, in _handle_result
django.db.utils.ProgrammingError: Table 'django_content_type' already exists

Answer

All the tables I should have are here now. This was what I did. I deleted all tables created in the database. I also removed usermie from INSTALLED_APPS. After that I ran python manage.py migrate. I am wondering if changing USE_TZ to False did anything as I have deleted the tables multiple times in the database before with no success. I also removed MySQL-connector-python-rf.

I still get these messages but all seems fine now:

(mie) C:\Users\dane_\DjangoProjects\pagemie>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying sessions.0001_initial... OK
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
    emit_post_migrate_signal(self.verbosity, self.interactive, connection.alias)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\core\management\sql.py", line 50, in emit_post_migrate_signal
    using=db)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\dispatch\dispatcher.py", line 192, in send
    response = receiver(signal=self, sender=sender, **named)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\contrib\auth\management\__init__.py", line 126, in create_permissions
    Permission.objects.using(using).bulk_create(perms)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\query.py", line 450, in bulk_create
    self._batched_insert(objs_without_pk, fields, batch_size)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\query.py", line 1056, in _batched_insert
    using=self.db)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\query.py", line 1039, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\sql\compiler.py", line 1059, in execute_sql
    for sql, params in self.as_sql():
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\django\db\models\sql\compiler.py", line 1047, in as_sql
    result.append(self.connection.ops.bulk_insert_sql(fields, placeholder_rows))
  File "C:\Users\dane_\DjangoVirtualEnvs\mie\lib\site-packages\mysql_connector_python_rf-2.1.3-py3.4-win-amd64.egg\mysql\connector\django\operations.py", line 223, in bulk_insert_sql
TypeError: can't multiply sequence by non-int of type 'tuple'
Comments