Forums

db.create_all() in virtual env results in no db change

Hi all,

I have a sqlite filebased database for my site that i manage with flask sql alchemy. I did a database change a couple of weeks ago from the virtual env bash by running pythin, importing the db module and running db.create_all()

Today I did a new release and while trying to do the same there was no resulting change in the db file. I also tried to add the db.create_all() in the file itself, but when I run it the file is run in Python 3.4 rather than my virtual environment (doh).

Any hint on what might be happening?

To run the code using your virtualenv, you'll need to start a Bash console and then run "workon your-virtualenv-name", or (as you're using the env in a web app), just click the "start a bash console in this virtualenv" link on the "Web" tab.

Regarding the database -- the create_all call is really designed to create a new database from scratch, so if it finds the tables are already in place (which is likely when you're working with your live site) then it won't do anything. To update an existing database, with data that you want to keep, you'll need to set up migrations. There's a Flask-migrate extension which is likely to be the best for that.