Answer the question
In order to leave comments, you need to log in
Why data is not saved in MySQL DB?
Good day to all!
I have this problem:
There is a model
class Test(models.Model):
"""
The model of the test
"""
# The name of the test
name = models.CharField(max_length=500)
# The description of test
description = models.TextField(blank=True)
# The test
test = models.BinaryField(blank=True)
# The author of the test
author = models.ForeignKey(settings.AUTH_USER_MODEL)
# The category of the test
category = models.ForeignKey(Category)
# date and time of create test
date_and_time = models.DateTimeField(default=timezone.now())
# How many users complete this test.
rating = models.IntegerField(default=0)
# Public or not public test
is_public = models.BooleanField(default=True)
def __str__(self):
return self.name
(django17)11:45 ~/exam_project (master)$ python3 populate_exam.py
Starting Exam population script...
Traceback (most recent call last):
File "populate_exam.py", line 214, in <module>
populate()
File "populate_exam.py", line 40, in populate
category1
File "populate_exam.py", line 208, in add_test
)[0]
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 422, in get_or_create
return self.get(**lookup), False
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 351, in get
num = len(clone)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 122, in __len__
self._fetch_all()
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 966, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
for rows in self.execute_sql(MULTI):
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/django/db/backends/utils.py", line 85, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/mysql/connector/django/base.py", line 377, in last_executed_query
return cursor.statement
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/mysql/connector/django/base.py", line 153, in __getattr__
return getattr(self.cursor, attr)
File "/home/alkutepov/.virtualenvs/django17/lib/python3.4/site-packages/mysql/connector/cursor.py", line 858, in statement
return self._executed.strip().decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 265: invalid start byte
(django17)11:45 ~/exam_project (master)$
Answer the question
In order to leave comments, you need to log in
If you have access to the console or some thread to manage databases like phpmyadmin, then try to run these commands
ALTER ИМЯ_ТВОЕЙ_БД `database_utf8` CHARACTER SET 'utf8';
ALTER ИМЯ_ТВОЕЙ_БД `database_utf8` COLLATE 'utf8_general_ci';
SELECT CONCAT( 'ALTER TABLE `', t.`TABLE_SCHEMA` , '`.`', t.`TABLE_NAME` , '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' ) AS sqlcode
FROM `information_schema`.`TABLES` t
WHERE 1
AND t.`TABLE_SCHEMA` = 'ИМЯ_ТВОЕЙ_БД'
ORDER BY 1
LIMIT 0 , 90
Because it is better to use PostgreSQL, MySQL has long outlived its usefulness, it is chosen if they do not know how PostgreSQL works, PostgreSQL is practically MS SQL just for free.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question