AttributeError: 'MySQLDatabase' object has no attribute 'create_table'
AttributeError: 'MySQLDatabase' object has no attribute 'create_table'
我正在尝试连接到 MySQL 数据库并创建 table:
import MySQLdb as mdb
from peewee import *
con = mdb.connect(host='127.0.0.1', user=db_user, db=db_name, passwd=db_pass)
database = MySQLDatabase(db_name, user=db_user, password=db_pass)
class BaseModel(Model):
class Meta:
database=database
class Foo(BaseModel):
inputId = CharField(primary_key=True, index=True)
inputContent = CharField()
database.connect()
database.create_table(Foo)
但是,当我 运行 上面的代码片段时,它给了我一个错误:
AttributeError Traceback (most recent call last)
<ipython-input-93-d0c7be80ee6f> in <module>()
14
15 database.connect()
---> 16 database.create_table(Foo)
AttributeError: 'MySQLDatabase' object has no attribute 'create_table'
有什么问题?
我在用
Python 2.7.18,小便 (3.10.0)
使用create_tables():
database.create_tables([Foo])
或者:
Foo.create_table()
文档中对此进行了非常简洁的介绍:http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-model-tables
我正在尝试连接到 MySQL 数据库并创建 table:
import MySQLdb as mdb
from peewee import *
con = mdb.connect(host='127.0.0.1', user=db_user, db=db_name, passwd=db_pass)
database = MySQLDatabase(db_name, user=db_user, password=db_pass)
class BaseModel(Model):
class Meta:
database=database
class Foo(BaseModel):
inputId = CharField(primary_key=True, index=True)
inputContent = CharField()
database.connect()
database.create_table(Foo)
但是,当我 运行 上面的代码片段时,它给了我一个错误:
AttributeError Traceback (most recent call last)
<ipython-input-93-d0c7be80ee6f> in <module>()
14
15 database.connect()
---> 16 database.create_table(Foo)
AttributeError: 'MySQLDatabase' object has no attribute 'create_table'
有什么问题? 我在用 Python 2.7.18,小便 (3.10.0)
使用create_tables():
database.create_tables([Foo])
或者:
Foo.create_table()
文档中对此进行了非常简洁的介绍:http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-model-tables