Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask sqlalchemy unknown database error

I'm trying to create a Web application using flask and flask-sqlalchemy, i have the following code

    from flask.ext.sqlalchemy import  SQLAlchemy
    from flask import Flask

    app= Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI']=            'mysql+mysqldb://root:[email protected]/testdb'
    db = SQLAlchemy(app)

When i run db.create_all() from command line, i get unknown database 'testdb' error I'm working on ubuntu but the code above works on my windows machine.

I've tried adding the port number, removing the python connector but nothing works. below is the stack trace

 File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
     return Connection(*args, **kwargs)
 File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
     super(Connection, self).__init__(*args, **kwargs2)
 sqlalchemy.exc.OperationalError: (OperationalError) (1049, "Unknown database 'testdb'") None None
like image 831
azdonald Avatar asked Sep 04 '13 01:09

azdonald


1 Answers

I would suggest that the database 'testdb' does not exist.

SQLAlchemy will not actually create the database for you. You have to connect to an existing database. It will then create all the tables.

Joe

like image 136
Joe Doherty Avatar answered Oct 16 '22 21:10

Joe Doherty