当我使用 my-app.appspot.com 时,我无法将表情符号发布到数据库
但是当我在本地运行它时 python manage.py runserver
在 GAE 上使用相同的库一切正常,我可以发布和检索表情符号。
这是我的设置.py
import os
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/my-app:us-central1:my-app-mysql',
'NAME': '********',
'USER': 'root',
'PASSWORD': '*********',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '*******',
'USER': 'root',
'PASSWORD': '*********',
'HOST': '**********',
'PORT': '3306',
'OPTIONS': {
'charset': 'utf8mb4',
}
}
}
这里是使用cloud shell时的字符集
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+--------------------------+--------------------+
10 rows in set (0.15 sec)
这是我从另一个客户端使用数据库的 IP 连接时的字符集
Variable_name Value
character_set_client utf8
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8
character_set_server utf8mb4
character_set_system utf8
collation_connection utf8mb4_unicode_ci
collation_database utf8mb4_general_ci
collation_server utf8mb4_general_ci
我是不是漏了什么?!!
我如何工作?
谢谢 https://github.com/GoogleCloudPlatform/appengine-django-skeleton/issues/28
最佳答案
waprin: @EssaAlshammri reproduced, filed internal bug with engineering team, will keep you updated.
来自 github issue
You can try base64 encoding going in and out of the database as a workaround.
它工作正常。
你可以等到他们解决问题
关于python - google CloudSQL mysql 表情符号(1366、 "Incorrect string value: '\\xF0\\x9F\\x98\\x80\\xF0\\x9F.. .' for column ' 名称'在第 1 行"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42389717/