Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing remote MySQL database with peewee

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

it hangs up on the second line, saying __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?

Thanks a lot, Alex

like image 989
Alex S Avatar asked May 08 '13 18:05

Alex S


People also ask

How do I access a remote database?

via cPanel To add your computer as an Access Host: Log in to cPanel. Under the Databases section, click on the Remote MySQL® icon. On the Remote MySQL® page, enter the connecting IP address, then click Add Host.

How do I connect to a MySQL database using IP address?

Select Connections from the SQL navigation menu. In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed. Note: The IP address of the instance and the mysql client IP address you authorize must be the same IP version: either IPv4 or IPv6. Click Done.


1 Answers

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

Thanks guys, Alex

like image 106
Alex S Avatar answered Oct 10 '22 17:10

Alex S