Error while migrating in django - python

I'm sorry, I don't think the title of my question is comprehensible as I'm absolutely a noob trying to understand django after LPTHW. Anyway, I'm following a tutorial in setting up Django to use MariaDB. But unfortunately when I run python manage.py migrate I get humongous block of error message. Here's the block:
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/2.1/ref/databases/#mysql-sql-mode
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1050, "Table 'django_content_type' already exists")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/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 "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/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 "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/migrations/operations/models.py", line 91, in database_forwards
schema_editor.create_model(model)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 312, in create_model
self.execute(sql, params or None)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 133, in execute
cursor.execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1050, "Table 'django_content_type' already exists")
Expecting another command to work after that error, I ran
python manage.py createsuperuser which returned me another block of error:
You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
Traceback (most recent call last):
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
_mysql_exceptions.ProgrammingError: (1146, "Table 'myproject.auth_user' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute
return super().execute(*args, **options)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 93, in handle
default_username = get_default_username()
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/contrib/auth/management/__init__.py", line 136, in get_default_username
auth_app.User._default_manager.get(username=default_username)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/models/query.py", line 393, in get
num = len(clone)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/models/query.py", line 250, in __len__
self._fetch_all()
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/models/query.py", line 1183, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1061, in execute_sql
cursor.execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/home/noob/Documents/projects/python/django/myproject/myprojectenv/lib/python3.5/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'myproject.auth_user' doesn't exist")
Could you help me solve this?

Related

I am not migrate in python django

Operations to perform:
Apply all migrations: admin, auth, contenttypes, main, sessions
Running migrations:
Applying main.0004_auto_20210301_2201...Traceback (most recent call last):
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 411, in execute
return Database.Cursor.execute(self, query)
sqlite3.OperationalError: no such function: JSON_VALID
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 "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-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\devia\AppData\Local\Programs\Python\Python38-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\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\operations\fields.py", line 236, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 138, in alter_field
super().alter_field(model, old_field, new_field, strict=strict)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 571, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type,
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 360, in _alter_field
self._remake_table(model, alter_field=(old_field, new_field))
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 280, in _remake_table
self.create_model(new_model)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 324, in create_model
self.execute(sql, params or None)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 142, in execute
cursor.execute(sql, params)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 411, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: no such function: JSON_VALID
here is the traceback. plz someone help me with this no able to migrate.
first i create a progres json field in table and did not work so i drop it. now everything is not working plz help with his
Models.py is blank
and everything is blank but not able to migrate
here is the traceback. plz someone help me with this no able to migrate.
first i create a progres json field in table and did not work so i drop it. now everything is not working plz help with his
Models.py is blank
and everything is blank but not able to migrate

Error (1062, "Duplicate entry '4' for key 'user_id'") on django loaddata

I just deleted my localhost database due to export my production website database and then import it to my lcoal db
I used this command to dump db:
./manage.py dumpdata --exclude contenttypes --exclude auth.permission
--exclude sessions --indent 2 > dump.json
and then on my localhost:
./manage.py loaddata dump.json
but I get error:
Traceback (most recent call last):
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 74, in execute
return self.cursor.execute(query, args)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.IntegrityError: (1062, "Duplicate entry '1' for key 'user_id'")
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/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 72, in handle
self.loaddata(fixture_labels)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 114, in loaddata
self.load_label(fixture_label)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 181, in load_label
obj.save(using=self.using)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/core/serializers/base.py", line 223, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/models/base.py", line 782, in save_base
updated = self._save_table(
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/models/base.py", line 887, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/models/base.py", line 924, in _do_insert
return manager._insert(
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1204, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1392, in execute_sql
cursor.execute(sql, params)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 74, in execute
return self.cursor.execute(query, args)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
res = self._query(query)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
db.query(q)
File "/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 239, in query
_mysql.connection.query(self, query)
django.db.utils.IntegrityError: Problem installing fixture '/home/mehdi/python/projects/FollowBotWebsite/v1.2.2/dump.json': Could not load users.Profile(pk=1): (1062, "Duplicate entry '1' for key 'user_id'")
I searched a lot but all soloutions were about permissions or auth, not my own models.
I used signals to make a profile for each user on creation,
solved this problem with addign not raw to my signals:
#receiver(post_save, sender=User)
def create_profile(sender, instance, created, raw=False, **kwargs):
if created and not raw:
Profile.objects.create(user=instance)
print('Profile Created')

Django migrating foreign keys django.db.utils.OperationalError: (1005, "Can't create table 'asp052mysqlpy.#sql-6ac_56' (errno: 150)") error

I'm trying to migrate a simple foreign key relation for a model in Django, but this results in a very strange and unsolvable error.
Error:
python manage.py migrate team
Operations to perform:
Apply all migrations: team
Running migrations:
Applying team.0001_initial... OK
Applying team.0002_auto_20191127_1643...Traceback (most recent call last):
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 255, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 252, in execute
res = self._query(query)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 378, in _query
db.query(q)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 280, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1005, "Can't create table 'asp052mysqlpy.#sql-6ac_56' (errno: 150)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\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\Mitch\Desktop\teamwork\teamworkapp\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\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\operations\fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\base\schema.py", line 523, in alter_field
old_db_params, new_db_params, strict)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\base\schema.py", line 744, in _alter_field
self.execute(self._create_fk_sql(model, new_field, "_fk_%(to_table)s_%(to_column)s"))
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\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\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 255, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 252, in execute
res = self._query(query)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 378, in _query
db.query(q)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 280, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1005, "Can't create table 'asp052mysqlpy.#sql-6ac_56' (errno: 150)")
Models:
class Tmteams(models.Model):
teamid = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
class Meta:
db_table = 'tmteams'
class Tmteamsusers(models.Model):
teamid = models.ForeignKey(Tmteams, on_delete=models.CASCADE, db_column='teamid')
userid = models.ForeignKey(User, on_delete=models.CASCADE, db_column='userid')
class Meta:
db_table = 'tmteamsusers'
unique_together = (('userid', 'teamid'),)
Migration file that errors:
class Migration(migrations.Migration):
dependencies = [
('team', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='tmteamsusers',
name='teamid',
field=models.ForeignKey(db_column='teamid', on_delete=django.db.models.deletion.CASCADE, to='team.Tmteams'),
),
migrations.AlterField(
model_name='tmteamsusers',
name='userid',
field=models.ForeignKey(db_column='userid', on_delete=django.db.models.deletion.CASCADE, to='users.User'),
),
]
I'm using the following modules and MySQL version:
Django 2.1.5
mysqlclient 1.3.14
MySQl 5.1.7.3 Community edition
Anyone that can help me out?
I've found and solved the problem. The table I'm referencing to (allmodusers) was still using the MyISAM database engine. I've changed the database engine of this table to InnoDB after reading the following article: https://kinsta.com/knowledgebase/convert-myisam-to-innodb/.

error when running python manage.py syncdb

I have a new server just installed. Everything seems to be fine but when i run:
python manage.py syncdb
it generates follow error:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/lib/python2.6/site-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/lib/python2.6/site-packages/django/contrib/auth/management/__init__.py", line 51, in create_permissions
content_type=ctype
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 138, in create
return self.get_query_set().create(**kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 360, in create
obj.save(force_insert=True, using=self.db)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 553, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 1436, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 791, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/usr/lib/python2.6/site-packages/MySQLdb/cursors.py", line 175, in execute
if not self._defer_warnings: self._warning_check()
File "/usr/lib/python2.6/site-packages/MySQLdb/cursors.py", line 89, in _warning_check
warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Incorrect string value: '\xE6\x99\xAF\xE9\xBB\x9E...' for column 'name' at row 1
All the tables and fields, in fact, created automatically without observable problem. I just wanna get rid of this error becoz the same thing does not happen in my old server with exactly the same project running on it.
So I am answering it here so that other people can have answer of same problem:
As said by Bill Kary:
He have solved this himself. Change all the collation of ALL tables AND fields to utf (utf8_general_ci) stops the error beautifully.

where does defined the Table 'test.sphinx_test_file'?

look the end line:ProgrammingError: (1146, "Table 'test.sphinx_test_file' doesn't exist")
Traceback (most recent call last):
File "D:\Python25\Lib\site-packages\django\core\servers\basehttp.py", line 280, in run
self.finish_response()
File "D:\Python25\Lib\site-packages\django\core\servers\basehttp.py", line 319, in finish_response
for data in self.result:
File "D:\Python25\Lib\site-packages\django\http\__init__.py", line 374, in __iter__
self._iterator = iter(self._container)
File "D:\zjm_code\sphinx_test\djangosphinx\models.py", line 240, in __iter__
return iter(self._get_data())
File "D:\zjm_code\sphinx_test\djangosphinx\models.py", line 404, in _get_data
self._result_cache = list(self._get_results())
File "D:\zjm_code\sphinx_test\djangosphinx\models.py", line 570, in _get_results
queryset = dict([(', '.join([unicode(getattr(o, p.attname)) for p in pks]), o) for o in queryset])
File "D:\Python25\Lib\site-packages\django\db\models\query.py", line 106, in _result_iter
self._fill_cache()
File "D:\Python25\Lib\site-packages\django\db\models\query.py", line 692, in _fill_cache
self._result_cache.append(self._iter.next())
File "D:\Python25\Lib\site-packages\django\db\models\query.py", line 238, in iterator
for row in self.query.results_iter():
File "D:\Python25\Lib\site-packages\django\db\models\sql\query.py", line 287, in results_iter
for rows in self.execute_sql(MULTI):
File "D:\Python25\Lib\site-packages\django\db\models\sql\query.py", line 2369, in execute_sql
cursor.execute(sql, params)
File "D:\Python25\Lib\site-packages\django\db\backends\util.py", line 19, in execute
return self.cursor.execute(sql, params)
File "D:\Python25\Lib\site-packages\django\db\backends\mysql\base.py", line 84, in execute
return self.cursor.execute(query, args)
File "D:\Python25\Lib\site-packages\MySQLdb\cursors.py", line 163, in execute
self.errorhandler(self, exc, value)
File "D:\Python25\Lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'test.sphinx_test_file' doesn't exist")
Did you run syncdb after adding the app (I'm guessing the app is named sphinx) to your settings.py?

Categories

Resources