python - 使用 peewee 访问远程 MySQL 数据库

标签 python amazon-rds peewee

我正在尝试使用 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__() 至少需要 2 个参数(1 个给定)

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

非常感谢,亚历克斯

最佳答案

我把它改成这样,它工作了:

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

谢谢各位, 亚历克斯

关于python - 使用 peewee 访问远程 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16448198/

相关文章:

python - Peewee 和 SQLite 返回错误的日期格式

python - 如何从peewee获取sql查询?

python - Mysql fetchall方法抛出 "Unread result found"异常

python - 在 imshow::matplotlib 中记录 x 尺度

在 Apache 中用于 Web 开发的 Python

amazon-web-services - 为什么 RDS 不使用 Amazon 根证书进行 SSL 连接

python - 在 Django 管理命令期间显示单行进度并在测试期间禁用它

amazon-rds - AWS RDS 使用的操作系统

aws-cloudformation - 在 CloudFormation 中获取 Aurora Serverless 集群 ARN(输出)

mysql - CompositeKey 作为 peewee 与 mysql 的外键