使用peewee访问远程MySQL数据库 [英] Accessing remote MySQL database with peewee
本文介绍了使用peewee访问远程MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用peewee连接到Amazon RDS上的MySQL数据库,但无法使其正常工作.我是数据库新手,所以我可能在做一些愚蠢的事情,但这就是我正在尝试的事情:
I'm trying to connect to a MySQL database on Amazon's RDS using peewee and I can't get it to work. I'm new to databases so I'm probably doing something stupid, but this is what I'm trying:
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)
我想念什么?为什么说我只给它一个参数,而我给它五个呢?
What am I missing? Why is it saying I'm only giving it one argument when I'm giving it five?
非常感谢Alex
推荐答案
我将其更改为这样,并且可以正常工作:
I changed it to be like this and it worked:
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()
谢谢大家, 亚历克斯
这篇关于使用peewee访问远程MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文