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

发布于 2024-08-24 12:47:11 字数 1446 浏览 8 评论 0原文

我正在使用 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 服务器发出的 echo 命令的列表:

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 ()

我已经搜索了解决方案,但找不到任何解决方案。

I'm using Elixir 0.7.1 , Sqlalchemy 0.6beta1 , MySQLdb 1.2.2.
My Model file 'model.py' looks like this:

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()

after executing : python model.py , no tables are created and no errors are thrown.
Here is a list of echo'd commands that are issued to the SQL server:

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 ()

I have searched for a solution and couldn't find any.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新一帅帅 2024-08-31 12:47:11

那么,您必须从 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))

Well, you have to inherit from the Entity base class (or from another base class of your choosing that use the EntityMeta metaclass).

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文