Python 使用peewee访问远程MySQL数据库

Python 使用peewee访问远程MySQL数据库,python,amazon-rds,peewee,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

我正在尝试使用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()
它挂在第二行,说
\uuuu init\uuuu()至少需要2个参数(给定1个)

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


非常感谢,Alex

我把它改成这样,效果很好:

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()
谢谢各位,
Alex

如您所述,max_length=None不正确。应该省略或max_length=您是对的,尽管它在上面有效,但当我尝试使用
User.create_table()
创建表时,它破坏了代码。我会把它从上面移除。谢谢!请问连接后如何从表中执行SELECT*操作?如何指定插入数据的表?