26

我正在尝试使用 peewee 连接到 Amazon 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)

我错过了什么?为什么它说我只给它一个论点而我给它五个?

非常感谢,亚历克斯

4

1 回答 1

38

我把它改成这样,它起作用了:

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

谢谢大家,亚历克斯

于 2013-05-08T21:31:22.250 回答