Django Python LoadData: Error Problem Installing Fixture - mysql

First I have migrate and makemigrations and then I have dump data with this command:
python manage.py dumpdata --exclude auth.permission --exclude contenttypes > dvvv.json
I have tried to flush the database but when I execute python manage.py loaddata dvvv.json the following error occurs:
pymysql.err.ProgrammingError: (1146, "Table 'webcnytc_prilert_tool.Prilert_confirmationemail' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
self.loaddata(fixture_labels)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 123, in loaddata
self.load_label(fixture_label)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 190, in load_label
obj.save(using=self.using)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/serializers/base.py", line 223, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 778, in save_base
force_update, using, update_fields,
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 859, in _save_table
forced_update)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 912, in _do_update
return filtered._update(values) > 0
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/query.py", line 802, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql
cursor = super().execute_sql(result_type)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/cursors.py", line 148, in execute
result = self._query(query)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/cursors.py", line 310, in _query
conn.query(q)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 775, in _read_query_result
result.read()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 725, in _read_packet
packet.raise_for_error()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.ProgrammingError: Problem installing fixture '/root/Django/dvvv.json': Could not load Prilert.ConfirmationEmail(pk=137): (1146, "Table 'webcnytc_prilert_tool.Prilert_confirmationemail' doesn't exist")

Related

MySQL Connection Error with Cpanel Hosting

I'm trying to connect my application with MySQL Database engine on Cpanel hosting platform but every time I tried to run makemigrations there's always this long error:
Traceback (most recent call last):
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/django/base.py", line 366, in get_new_connection
cnx = mysql.connector.connect(**conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/pooling.py", line 286, in connect
return CMySQLConnection(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/connection_cext.py", line 101, in __init__
self.connect(**kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1099, in connect
self._post_connection()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1071, in _post_connection
self.set_charset_collation(self._charset_id)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1016, in set_charset_collation
) = CharacterSet.get_charset_info(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 775, in get_charset_info
info = cls.get_default_collation(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 746, in get_default_collation
raise ProgrammingError(f"Character set '{charset}' unsupported")
mysql.connector.errors.ProgrammingError: Character set '255' unsupported
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home2/cmsmcsc1/cmsmcs/manage.py", line 22, in <module>
main()
File "/home2/cmsmcsc1/cmsmcs/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/base.py", line 98, in wrapped
res = handle_func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 119, in handle
loader.check_consistent_history(connection)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/migrations/loader.py", line 313, in check_consistent_history
applied = recorder.applied_migrations()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 284, in cursor
return self._cursor()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 260, in _cursor
self.ensure_connection()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 244, in ensure_connection
self.connect()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib/python3.9/site-packages/django/db/backends/base/base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/django/base.py", line 366, in get_new_connection
cnx = mysql.connector.connect(**conn_params)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/pooling.py", line 286, in connect
return CMySQLConnection(*args, **kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/connection_cext.py", line 101, in __init__
self.connect(**kwargs)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1099, in connect
self._post_connection()
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1071, in _post_connection
self.set_charset_collation(self._charset_id)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/abstracts.py", line 1016, in set_charset_collation
) = CharacterSet.get_charset_info(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 775, in get_charset_info
info = cls.get_default_collation(charset)
File "/home2/cmsmcsc1/virtualenv/cmsmcs/3.9/lib64/python3.9/site-packages/mysql/connector/constants.py", line 746, in get_default_collation
raise ProgrammingError(f"Character set '{charset}' unsupported")
django.db.utils.ProgrammingError: (-1, "Character set '255' unsupported", None)
Does anyone knows what to do, please?
try it it will definitely helps you
run the command in your Cpanel Hosting Terminal
pip3 install mysql-connector-python==8.0.29

django.db.utils.OperationalError: (1054, "Unknown column 'commons_smsmessages.sent_date' in 'field list'")

I'm using mysql as a db and I'm getting a django.db.utils.OperationalError: (1054, "Unknown column 'commons_smsmessages.sent_date' in 'field list'") when I add a field to the a pre-existing model. How do I fix it?
I tried python manage.py makemigrations and I've also tried deleting all the migration files and running python manage.py makemigrations but it doesn't seem to work.
This is the model I'm trying to update/add a field to:
class SMSMessages(models.Model):
sms_number_to = models.CharField(max_length=14)
sms_content = models.CharField(max_length=160)
sender_company = models.ForeignKey("SMSUser", on_delete=models.PROTECT, related_name="company_that_sent", limit_choices_to=1)
sent_date = models.DateTimeField(auto_now=True)
class Meta:
verbose_name_plural = "SMSMessages"
def __str__(self):
return self.sender_company
The field I'm trying to add to the model is sent_date. But whenever I run python manage.py makemigrations I get the error
Traceback (most recent call last):
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/MySQLdb/connections.py", line 226, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1054, "Unknown column 'commons_smsmessages.sent_date' in 'field list'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
self.check()
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/urls/resolvers.py", line 399, in check
for pattern in self.url_patterns:
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/urls/resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api/urls.py", line 23, in <module>
path("", include('commons.urls')),
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/commons/urls.py", line 8, in <module>
from commons.apiviews import TypeList, TypeDetail, SMSPriceList, SMSPriceDetail, SMSUserCreate, SMSUserUpdate
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/commons/apiviews.py", line 135, in <module>
class SMSMessagesView(generics.ListCreateAPIView):
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/commons/apiviews.py", line 142, in SMSMessagesView
if not queryset:
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/models/query.py", line 278, in __bool__
self._fetch_all()
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/models/query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1100, in execute_sql
cursor.execute(sql, params)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/gadd/vscodeworkspace/sms.et/api.sms.et/api_env/lib/python3.6/site-packages/MySQLdb/connections.py", line 226, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1054, "Unknown column 'commons_smsmessages.sent_date' in 'field list'")
What I was expecting is the python manage.py makemigrations to successfully run, update my db, and add the column to the model/table.
So I've have solved right after posting the question. so turns out, God know why, if you use the model you're trying to update anywhere then django will throw the above error (again God knows why). So I commented out the code blocks that use the above model in the views.py, serializer.py, apiviews.py etc etc files and run python manage.py makemigrations, It worked.
I left here just in-case someone else runs into this problem.

Table 'auth_user' already exits , when I try to migrate new tables to my local mysql database

I am trying to deploy a Django project on my local machine.As far as I know, when I run migrate command, my_app tables along with django's table should be visible in my local database. When I run makemigration app_name command, I can see the correct SQL query is generated for my table. However, when I run migrate command, I get the error
table 'auth_user' already exists
My database is empty before I run this.
Also my migration folder has just the init.py file.
Following is the Error Log i get:
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, impact_mapping, sessions
Running migrations:
Applying impact_mapping.0001_initial...Traceback (most recent call last):
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\mysql\base.py", line 101, in execute
return self.cursor.execute(query, args)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\MySQLdb\cursors.py", line 209, in execute
res = self._query(query)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\MySQLdb\cursors.py", line 315, in _query
db.query(q)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\MySQLdb\connections.py", line 226, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1050, "Table 'auth_user' already exists")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
fake_initial=fake_initial,
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\migrations\executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\migrations\executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\migrations\operations\models.py", line 97, in database_forwards
schema_editor.create_model(model)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\base\schema.py", line 319, in create_model
self.execute(sql, params or None)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\base\schema.py", line 136, in execute
cursor.execute(sql, params)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\django\db\backends\mysql\base.py", line 101, in execute
return self.cursor.execute(query, args)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\MySQLdb\cursors.py", line 209, in execute
res = self._query(query)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\MySQLdb\cursors.py", line 315, in _query
db.query(q)
File "C:\Users\dpanch378\CBAT\component_mapping\env\lib\site-packages\MySQLdb\connections.py", line 226, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1050, "Table 'auth_user' already exists")
(env)
Expected Outcome:I should get all the tables in my database
Actual Outcome: I get the error that auth_user table already exists.

Django: 1215, 'Cannot add foreign key constraint' on model with only one field

I have a Salad model:
class Salad(models.Model):
some_field = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
No matter how I call the class, the single field, what models I put instead of Profile, or whichever on_delete option I choose. I systematically get the error:
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')
The error log:
Traceback (most recent call last):
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
Applying playerdata.0053_auto_20180724_1943... return self.cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 292, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pycharm\django_manage.py", line 52, in <module>
run_command()
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:/Python/DjangoProjects/rolegate\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
fake_initial=fake_initial,
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 90, in __exit__
self.execute(sql)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 117, in execute
cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 292, in query
_mysql.connection.query(self, query)
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')
Normally it is caused by the fact that your two related tables are not using InnoDB and at least one of them uses MyISAM engine instead.
The problem is Foreign keys are not supported on MyISAM.
Here is a related Django ticket #26777.
Since this is entirely related to MYSQL and not a Django specific, I will link this thread that could potentially help you,
Converting Tables from MyISAM to InnoDB
FUN FACT
I'm not the one that took care of this Django ticket even if the names are similar. #SimonCharette is.

Getting ""Duplicate column name" error in Django for no apparent reason

I've looked here and through Google, and found nothing that seems to describe what I'm seeing. I'm using Django 1.7 with Python 3.4.
ETA: I'm using MySQL 5.6.17
I have the following model (unrelated fields left out):
class Location(models.Model):
location_type = models.CharField(max_length=5,
choices=constants.LocationTypes.LOCATION_CHOICES
)
parent = models.ForeignKey("Location", blank=True, null=True, related_name='location_parent')
room = models.ForeignKey("Location", blank=True, null=True, related_name='location_room')
There are no other instances of "room" anywhere else in models.py except for a comment.
It worked fine until I added the room field (adding the related _name to parent at the same time). Now when I try to run the migration, I get the following:
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 128, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 132, in execute result = self._query(query)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 271, in _query conn.query(q)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 726, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 861, in _read_query_result result.read()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 1064, in read first_packet = self.connection._read_packet()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 826, in _read_packet packet.check_error()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 370, in check_error raise_mysql_exception(self._data)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue)
pymysql.err.InternalError: (1060, "Duplicate column name 'room_id'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/Phoenix/PycharmProjects/gamecon/manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 338, in execute output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 160, in handle executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 63, in migrate self.apply_migration(migration, fake=fake)
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 97, in apply_migration migration.apply(project_state, schema_editor)
File "C:\Python34\lib\site-packages\django\db\migrations\migration.py", line 107, in apply operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py", line 37, in database_forwards field,
File "C:\Python34\lib\site-packages\django\db\backends\mysql\schema.py", line 42, in add_field super(DatabaseSchemaEditor, self).add_field(model, field)
File "C:\Python34\lib\site-packages\django\db\backends\schema.py", line 390, in add_field self.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\schema.py", line 99, in execute cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 81, in execute return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 549, in reraise raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 128, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 132, in execute result = self._query(query)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 271, in _query conn.query(q)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 726, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 861, in _read_query_result result.read()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 1064, in read first_packet = self.connection._read_packet()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 826, in _read_packet packet.check_error()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 370, in check_error raise_mysql_exception(self._data)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue)
django.db.utils.InternalError: (1060, "Duplicate column name 'room_id'")
Can someone please tell me what I'm missing here?
Made answer from comment
if you are doing ForeignKey on the model itself you should do it like this
models.ForeignKey("self", blank=True, null=True, related_name='location_parent')