To run this application, follow these steps:
-
Create a
.env
File:Create a file named
.env
in the root directory of your project. -
Insert the Following Credentials:
Open the
.env
file and insert the following lines, replacing the placeholders with your actual credentials:# .env DEBUG=True PORT=5000 HOST=0.0.0.0 DB_URI=postgresql://postgres:root@localhost:5432/TaskManager SECRET_KEY=your_flask_secret_key SQLALCHEMY_TRACK_MODIFICATIONS=False RESULT_BACKEND=rpc:// BROKER_URL=pyamqp://guest:guest@localhost:5672//
Adjust these values based on your specific database and application configuration.
-
Save and Close the File:
Save the changes to the
.env
file and close it.
Below are the common commands used for managing database migrations in a Flask application using Flask-Migrate and Flask-Script.
-
Initialize the Migration Repository:
python manage.py db init
This command initializes a new migration repository. Run this command only once when setting up your project.
-
Generate a Migration:
python manage.py db migrate -m "Your migration message"
This command generates a new migration based on changes in your models. Run this command every time you make changes to your database models.
-
Apply Migrations:
python manage.py db upgrade
This command applies any pending migrations to the database.
-
Downgrade a Migration:
python manage.py db downgrade
This command rolls back the last applied migration. Use it with caution, especially in production environments.
-
Show the List of Migrations:
python manage.py db history
This command displays a list of migrations and their statuses.
-
Show the Current Revision:
python manage.py db current
This command shows the current revision of the database.