Open Valuebai opened 3 years ago
# 获取当前时间
current_time = time.strftime('%Y-%m-%d-%H:%M:%S', time.localtime(time.time()))
final_file = r'./data/merged_file_{}.txt'.format(current_time)
print(final_file)
# 2个文本合并后的路径,需要考虑放在哪里,暂时以w_file 或当前路径下/data/文件夹中
w_file = open(final_file, "wb")
Applying django_celery_results.0001_initial...Traceback (most recent call last): ... django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 1000 bytes')
【原因】在数据库中创建的表是MyISAM,而不是InnoDB
【解决】将表设置为InnoDB
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
DATABASES['default']['OPTIONS'] = {
"init_command": "SET default_storage_engine=INNODB;"
}
或者
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', '
sqlite3' or 'oracle'.
'OPTIONS':{
"init_command": "SET default_storage_engine=INNODB;"
},
'NAME': 'mydb', # Or path to database file if using sqlite3.
'USER': 'mmog', # Not used with sqlite3.
'PASSWORD': 'mmog', # Not used with sqlite3.
'HOST': '/data/mysqldata/mysql.sock', # Set to empty string for localh
ost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
如:
# timeout为过期时间,单位:秒,timeout=0为立即过期, timeout为None永不超时
set_flag = cache.set(self.redis_key, token_value, timeout=self.expire_time)
查看值:
\x80\x04\x95\x16\x00\x00\x00\x00\x00\x00\x00}\x94\x8c\x09mip_token\x94\x8c\x03123\x94s.
原因:django_redis对set的key进行的picke序列化和base64encode操作
python3.6/site-packages/django/core/cache/backends/db.py 的140行
if num > self._max_entries:
self._cull(db, cursor, now)
pickled = pickle.dumps(value, self.pickle_protocol)
# The DB column is expecting a string, so make sure the value is a
# string, not bytes. Refs #19274.
b64encoded = base64.b64encode(pickled).decode('latin1')
Django 常见报错,比较难找到原因的