Accessing remote MySQL database with peewee

前端 未结 1 1639
醉梦人生
醉梦人生 2021-02-01 04:44

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

1条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 05:17

    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

    0 讨论(0)
提交回复
热议问题