Reputation: 29
I am creating a user table using flask_sqlalchemy and trying to migrate using flask_migrate. But no user table is created . .db file has been generated in project directory but in migration/version no version has been generated. How to resolve this issue ?
I followed these articles , but I did not find the solution . Here are the articles :- https://flask-migrate.readthedocs.io/en/latest/ https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database
from flask import Flask
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app,db)
from app import routes
I got this output on my Terminal flask db migrate -m 'users'
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.env] No changes in schema detected.
and expected output was :
(venv) $ flask db migrate -m "users table"
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table 'user'
INFO [alembic.autogenerate.compare] Detected added index 'ix_user_email' on '['email']'
INFO [alembic.autogenerate.compare] Detected added index 'ix_user_username' on '['username']'
Generating /home/miguel/microblog/migrations/versions/e517276bb1c2_users_table.py ... done
Upvotes: 0
Views: 321
Reputation: 121
I just ran into the same problem. If you look at the import statement on the bottom of __init__.py, you didn't add the 'models' module, so it doesn't know about the new data model you created.
This is what __init__.py should look like at this point in the tutorial:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from config import Config
app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
from app import routes, models
Upvotes: 2