Elixir create_all()不创建数据库和表

时间:2010-03-07 01:08:33

标签: python sqlalchemy python-elixir

我正在使用Elixir 0.7.1,Sqlalchemy 0.6beta1,MySQLdb 1.2.2。 我的模型文件'model.py'如下所示:

from elixir import *
from datetime import datetime

class Author:
  first_name = Field(Unicode(64))
  last_name = Field(Unicode(64))

class Article:
  title = Field(Unicode(64))

class Category:
  name = Field(Unicode(64))

setup_all()
metadata.bind = "mysql://user:pass@localhost/dbname"
metadata.bind.echo = True

create_all()
metadata.create_all()

执行:python model.py后,不会创建任何表,也不会抛出任何错误。 以下是发布到SQL Server的echo'd命令列表:

2010-03-06 19:50:22,004 INFO sqlalchemy.engine.base.Engine.0x...6c4c SELECT DATABASE()
2010-03-06 19:50:22,004 INFO sqlalchemy.engine.base.Engine.0x...6c4c ()
2010-03-06 19:50:22,005 INFO sqlalchemy.engine.base.Engine.0x...6c4c SHOW VARIABLES LIKE 'character_set%%'
2010-03-06 19:50:22,005 INFO sqlalchemy.engine.base.Engine.0x...6c4c ()
2010-03-06 19:50:22,006 INFO sqlalchemy.engine.base.Engine.0x...6c4c SHOW VARIABLES LIKE 'lower_case_table_names'
2010-03-06 19:50:22,006 INFO sqlalchemy.engine.base.Engine.0x...6c4c ()
2010-03-06 19:50:22,007 INFO sqlalchemy.engine.base.Engine.0x...6c4c SHOW COLLATION
2010-03-06 19:50:22,007 INFO sqlalchemy.engine.base.Engine.0x...6c4c ()
2010-03-06 19:50:22,009 INFO sqlalchemy.engine.base.Engine.0x...6c4c SHOW VARIABLES LIKE 'sql_mode'
2010-03-06 19:50:22,010 INFO sqlalchemy.engine.base.Engine.0x...6c4c ()

我搜索了一个解决方案但找不到任何解决方案。

1 个答案:

答案 0 :(得分:1)

好吧,你必须继承Entity基类(或者你选择的另一个使用EntityMeta元类的基类)。

class Author(Entity):
    first_name = Field(Unicode(64))
    last_name = Field(Unicode(64))

class Article(Entity):
    title = Field(Unicode(64))

class Category(Entity):
    name = Field(Unicode(64))