Comments (11)
@joekendal You don't need manage.py in this case. "flask db init" and etc will do what you want. https://flask-migrate.readthedocs.io/en/latest/
from flask-migrate.
You can use init_app()
with Flask-Migrate. Note that the extension requires the app and database instances as arguments, not just the app.
from flask-migrate.
I guess I should have expanded. I would like to be able to pass a config arg to the create app through the manager options. For example, if I wanted to specify a local db instead of production db.
def create_app(config):
# load config
return app
python app.py db migrate -config test
python app.py db migrate -config production
Maybe this is possible already, I'll take another look.
from flask-migrate.
@JustinWP I prefer to set the configuration in an environment variable, but I think you can do what you want through Flask-Script's root level options. See http://flask-script.readthedocs.org/en/latest/#adding-options-to-the-manager.
from flask-migrate.
Closing due to inactivity.
from flask-migrate.
I actually had the same question in mind : How can I specify the configuration option in comand line and still use FlaskMigrate... So I ll post the details here in case it helps make the issue clearer.
The problem comes from the fact that I need, in this order :
app
db
- and then
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
However adding a config option to a command will change db
, and therefore when calling :
python manage.py -c dev.cfg db migrate
, in my command ('db' ?) I need to :
- run my app factory method
app = create_app()
- set the config from the option
app.config.from_pyfile('dev.cfgs')
- initialize the db using that app
db = init_db(app)
- then from my command method, I need to call the original migrate code from Flask Migrate, but on the new
db
object => How ? Inherit from MigrateCommand ? using it as delegate and just call a few methods ? in which order ?
While surely doable, How is at least not obvious for a new comer...
from flask-migrate.
I answered a similar question on StackOverflow: http://stackoverflow.com/a/29882346/904393. Let me know if this doesn't answer all your questions.
from flask-migrate.
Great, thats what I was missing. Thanks a lot !
from flask-migrate.
@miguelgrinberg Hi I did all of this and yet it is still not working for some reason
project/__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
db = SQLAlchemy()
migrate = Migrate()
def create_app():
app = Flask(__name__)
app.config.from_object(os.environ['APP_SETTINGS'])
db.init_app(app)
migrate.init_app(app, db)
return app
manage.py
from flask_script import Manager
from flask_migrate import MigrateCommand
from project import create_app
manager = Manager(create_app)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
manager.run()
Running the following still doesn't detect my models and then create tables:
> python manage.py db migrate
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
>
from flask-migrate.
usage: run.py [-?] {db,shell,runserver} ...
run.py: error: invalid choice: 'migrate' (choose from 'db', 'shell', 'runserver')
me to also also same problem.
from flask-migrate.
@dayastark try run.py db migrate
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.