mysql pyramid initialise db 使用有效数据生成无效语法

标签 mysql sqlalchemy python-3.2

我制作了一个金字塔应用程序,它使用 sqlite3 运行良好。对于生产,我需要使用 mysql。

在我的 initialize_db 脚本中,我创建了一个用户。运行脚本会产生以下错误:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s, %s, %s, %s, %s, %s, %s)' at line 1") b'INSERT INTO auth_users (email_address, username, salt, password, is_staff, is_super, is_active) VALUES (%s, %s, %s, %s, %s, %s, %s)' ('stuff@gmail.com', 'admin', '1371576670.410974', "b'S\\x1a\\x12\\xab\\xa2a\\x12\\xffF~\\xd98\\xcd1\\xf4l'", 1, 1, 1)

但是,如果我使用 mysql shell,则效果很好:

INSERT INTO auth_users (email_address, username, salt, password, is_staff, is_super, is_active) VALUES  ('stuff@gmail.com', 'admin', '1371576670.410974', "b'S\\x1a\\x12\\xab\\xa2a\\x12\\xffF~\\xd98\\xcd1\\xf4l'", 1, 1, 1);

auth_user 的表如下所示:

class User(Base,BaseExtension):
    __tablename__ = 'auth_users'
    id              = Column(Integer,Sequence('user_seq'), primary_key=True)
    email_address   = Column(String(255))
    username        = Column(String(50))
    salt            = Column(String(20))
    #password        = Column(Unicode(40))
    password        = Column(LargeBinary(17))
    is_staff        = Column(Boolean)
    is_super        = Column(Boolean)
    is_active       = Column(Boolean)

新用户创建如下:

        super1 = User('sheena.oconnell@gmail.com','some_password_that_gets_salted_and_md5ed')
        super1.username = 'admin'
        super1.is_active = True
        super1.is_super = True
        super1.is_staff = True
        DBSession.add(super1)
        super1.groups.append = UserGroup('super')

我正在运行 Python3.2 并使用 mysql for python 3作为司机。

有什么想法吗?

最佳答案

现在我要继续:那个驱动程序坏了。

将 oursql 用于 python3 工作正常。

关于mysql pyramid initialise db 使用有效数据生成无效语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17175519/

相关文章:

php - 如何在 LIMIT 子句中应用 bindValue 方法?

MySQL 查询 3 表内部连接只返回 1 行

python - 如何在不转换为列表的情况下替换 python 字符串中特定位置的字母?

python - 升级 Pyramid/SQLAlchemy 网络应用程序

python - Windows 上的 Python 2.6 和 3.2 urlopen 例程的问题

gtk3 - Python/Gtk3 : How to add a Gtk. 进入 Gtk.MessageDialog?

mysql - magento1.4v 和 1.5v 数据库的区别

JavaScript 正则表达式用于验证接收到的 MySQL 全文搜索搜索字符串

python - sqlalchemy,如果它不存在则创建一个 sqlite 数据库

python - 如何使用 Flask SQLAlchemy 查询多对多