Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can peewee create a new MySQL database

I've looked through all the docs I could find, and read the source code...and it doesn't seem you can actually create a MySQL database (or any other kind, that I could find) using peewee. If so, that means for any the database I may need to connect to, I would need to create it manually using mysql or some other tool.

Is that accurate, or am I missing something?

like image 506
zaisha Avatar asked Aug 08 '14 00:08

zaisha


3 Answers

Peewee can create tables but not databases. That's standard for ORMs, as creating databases is very vendor-specific and generally considered a very administrative task. PostgreSQL requires you to connect to a specific database, Oracle muddles the distinction between users and databases, SQLite considers each file to be a database...it's very environment specific.

like image 175
Steve McKay Avatar answered Oct 13 '22 09:10

Steve McKay


You can't create a MySQL database with peewee, but you can do it programatically with other libraries, for example with PyMySQL.

import pymysql

conn = pymysql.connect(host='host', user='user', password='password')
conn.cursor().execute('CREATE DATABASE mydb')
conn.close()
like image 21
cavendish Avatar answered Oct 13 '22 09:10

cavendish


Peewee cannot create databases with MySql or with other systems that require database and user setup, but will create the database with sqlite when the first table is created.

like image 3
stenci Avatar answered Oct 13 '22 08:10

stenci