Comments (17)
Unfortunately I could not easily run your code to test it, it seems there are several things that need to be provided in the environment.
Models are typically imported in the app package, so basically in the __init__.py
file.
from flask-migrate.
You know what, I think I know what's going on. Did you try deleting your database? If the database matches your model definition then Alembic will not detect any changes.
from flask-migrate.
Just as a test, define a quick model in __init__.py
, something like:
class Test(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(64))
and see if that is recognized by the migration.
from flask-migrate.
One more tip, I met the same problem, but my solution is to check the module load order.
if your model definition python script,( such as XXX.py) is not in the app init load process, it will not find the model you create.
The case like, you import db to app.py and use db.init(app), but the model definition is ingnored.
so you better import the model-define python script into your app.py.
from flask-migrate.
Does calling db.create_all() from a shell create your tables?
I think it won't either. It seems your model(s) aren't getting imported, so SQLAlchemy and Alembic do not see them.
from flask-migrate.
Yes, doing a db.create_all() creates all of my tables via the shell.
Where would I have to import my models?
from flask-migrate.
Ah, sorry about the env
issue. I'll work on that and get back to you.
from flask-migrate.
Sure thing. Should I create the table before I generate the migration or would that even matter in this case?
from flask-migrate.
Success!
"""empty message
Revision ID: 4be2ca3324b2
Revises: None
Create Date: 2013-09-17 23:47:37.470241
"""
# revision identifiers, used by Alembic.
revision = '4be2ca3324b2'
down_revision = None
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('test',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('test')
### end Alembic commands ###
from flask-migrate.
I'll see if this works for my users module as well.
from flask-migrate.
If you want your user model to be in the migration you need to remove it from the database. Once you enable migrations all changes to the db need to be done by the migration scripts
from flask-migrate.
Done. I imported my user models at the very bottom of the __init__.py
with a simple from calpoly.users import models
. However, I now end up with this error (after deleting my users table):
INFO [alembic.migration] Context impl PostgresqlImpl.
INFO [alembic.migration] Will assume transactional DDL.
Traceback (most recent call last):
File "manage.py", line 4, in <module>
manager.run()
File "/home/robin/github/ieee/lib/python2.7/site-packages/flask_script/__init__.py", line 366, in run
raise e
alembic.util.CommandError: Target database is not up to date.
from flask-migrate.
This was alleviated by removing some already existing versions.
Thanks for all the help and the quick responses! 👍
from flask-migrate.
@brotatos I have same issue, But I dont' need to import models in the init.py file, I just need import views on the init.py and then in the views.py I import the models.
from flask-migrate.
@brotatos you need to run alembic upgrade head
to avoid the alembic.util.CommandError: Target database is not up to date.
I suppose the tool requires you apply existing migrations before creating new ones
from flask-migrate.
For my first Database migration. I was facing some error after "flask db migrate -m "users table". Then I set FLASK_APP to the value microblog.py Then error was resolved and got the output as yours.
My doubt: When I have followed all the steps for "automatic import of envirnoment variable" and created ".flaskenv" then why am I supposed to set FLASK_APP value manually. Am I missing something?
from flask-migrate.
When I have followed all the steps for "automatic import of envirnoment variable" and created ".flaskenv" then why am I supposed to set FLASK_APP value manually.
If you have python-dotenv installed in your environment and have a .flaskenv file, then there is no need to manually set FLASK_APP.
from flask-migrate.
Related Issues (20)
- Upgrade problems; Online migration expected to match one row error HOT 1
- Alembic upgrade head in infinite loop HOT 1
- Migrations sometimes end with status 1 HOT 4
- How to check if models are in sync with generated migrations? HOT 1
- Type hints HOT 2
- [4.0] app factory is called before click groups HOT 6
- flask db migrate taking ~30min to autogenerate and throwing unrelated warnings HOT 2
- How is this possible?
- Failure to run flask db migrate after upgrade 3.1 -> 4.0 HOT 4
- Custom Template is not included in the sdist HOT 1
- Compatibility with sqlalchemy v2 HOT 5
- DeprecationWarning: 'get_engine' is deprecated HOT 5
- Enum Field changes, but no changes in schema detected when run "flask db migrate" HOT 1
- Do not automatically import of sqlalchemy_utils HOT 1
- The pgvector vector field cannot generate a normal migration script HOT 1
- An error was reported during migration
- [Feature request] Move `process_revision_directives` to `alembic_ctx_kwargs` HOT 2
- Problems connecting to Postsgress Because of no encryption HOT 5
- No such command 'db'
- db.create_all() not working with PostgreSQL on windows platform HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-migrate.