-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run "Create" without changes breaks the code #10
Comments
Yes, that's the right functionality. Running If you add a column to your model, you'll need to generate a new migration and add the
Then update your migration: def upgrade(migrator):
migrator.add_column('tweet', 'content', 'text')
def downgrade(migrator):
migrator.drop_column('tweet', 'content') |
|
I think it would be a great feature to have. I have no plans to implement it, mostly because I don't have time to dedicate to it. I have given it much thought though. There are many different changes to a model that could take place like...
Django and Alembic have both solved this, but using different strategies. Django keeps track of model history (it knows what your models look like before each change). I wouldn't be opposed to doing something like that, but it's definitely more complex. Adding a column and removing a column are the easiest to detect and quite common actions, so even if it were able to do that, I think it would be helpful. I will gladly accept pull requests for this feature (or any other feature for that matter). I don't use this library too often anymore, but if it's useful to other people I'd like to keep it alive. I'd be glad to help with development as well, I just don't have time to do it completely in any reasonable time frame. |
When you create a migration for the first time it does it correctly. Then if you make changes somewhere and create the migration and update the database, the unmodified tables detect them as new.
Example:
Create the model (models.py):
Create the migration (console)
flask-db create app.models
and you get:
INFO: created: 0001_create_table_user
INFO: created: 0002_create_table_tweet
Apply the migration to the DB (console):
flask-db upgrade
and you get
INFO: all migrations applied!
Now, you want to make a change in the model (models.py)
Create the new migration
flask-db create app.models
and you get:
INFO: created: 0003_create_table_user
INFO: created: 0004_create_table_tweet
Apply new migration to the DB:
flask-db upgrade
and get
INFO: upgrade: 0003_create_table_user
ERROR: table "user" already exists
The text was updated successfully, but these errors were encountered: