SLQAlchemy, Flask: AttributeError: 'module' object has no attribute 'create_all'

时间:2015-05-24 20:36:41

标签: virtualenv flask-sqlalchemy

I'm having this issue when creating the tables using SQLAlquemy in Flask, in a virtualenv.

I do:

>>> from mod_db import modelx
>>> modelx.create_all()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'create_all'

modelx is:

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

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://gaz:123@localhost:5432/test'
db = SQLAlchemy(app)

db classes...

What can it be?

Thanks!

1 个答案:

答案 0 :(得分:1)

If you’re trying to use the create_all on db, that’d be it.

modelx.db.create_all()