使用peewee访问远程MySQL数据库

时间:2013-05-08 18:58:47

标签: python amazon-rds peewee

我正在尝试使用peewee连接到亚马逊RDS上的MySQL数据库,我无法让它工作。我是数据库的新手,所以我可能做了一些愚蠢的事情,但这就是我正在尝试的事情:

import peewee as pw

myDB = pw.MySQLDatabase(host="mydb.crhauek3cxfw.us-west-2.rds.amazonaws.com",port=3306,user="user",passwd="password",db="mydb")


class MySQLModel(Model):
    """A base model that will use our MySQL database"""
    class Meta:
        database = myDB

class User(MySQLModel):
    username = CharField()

myDB.connect()

它挂在第二行,说__init__() takes at least 2 arguments (1 given)

我错过了什么?为什么说我只给它一个参数当我给它五个?

非常感谢,Alex

1 个答案:

答案 0 :(得分:29)

我改变它是这样的,它起作用了:

import peewee as pw

myDB = pw.MySQLDatabase("mydb", host="mydb.crhauek3cxfw.us-west-2.rds.amazonaws.com", port=3306, user="user", passwd="password")

class MySQLModel(pw.Model):
    """A base model that will use our MySQL database"""
    class Meta:
        database = myDB

class User(MySQLModel):
    username = pw.CharField()
    # etc, etc


# when you're ready to start querying, remember to connect
myDB.connect()

谢谢你们, 亚历