Home  >  Q&A  >  body text

python - flask如何创建中文列名的数据表

我使用python+flask+mysql创建了一个web应用,需要实现把mysql中的内容显示在html上。
因为数据库中student数据表的列名需要用中文,所以我写了如下代码model.py中:
首行有#--coding:utf-8--,mysql字符集也是utf8
from app import db

class Student(db.Model):

'姓名'=db.Colunm(db.String(20))
'性别'=db.Colunm(db.String(10))

db.create_all()

运行后报错,应该如何处理呀,列名必须用中文

高洛峰高洛峰2741 days ago840

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-18 10:30:33

    Is it necessary to specify the primary key when creating a data table with flask-sqlalchemy? I want to create a table without a primary key. Is that okay?

    reply
    0
  • Cancelreply