# 06 - Making Migrations

## Creating our own Manager Script

Django's `manage.py` file is amazing. It comes with many different commands and flags and options that do anything you could possibly need while making a full stack web app. Flask is not so great, and doesn't come with a `manage.py` file. But, that doesn't mean we can't make one ourselves. Our `manage.py` is going to sit in the base directory (just like Django's), and will aid us with migrations.

Consider the following code and plug it into your `manage.py` file

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPgkeF2WmGfIA0W3U%2Fmanage_py.jpg?generation=1554147629726199\&alt=media)

Remember, if you come back to the gitbook later on, or have had to restart your PC, you will lose your environment variables. This means that your computer has forgotten what your `DATABASE_URL` is and you will need to re-add them by following the steps in `02 - Chief Configuration`

In this file, we are creating utilizing Flask-Script and Flask-Migrate. These are Flask Extensions made to give us some great quality of life features. One of these features is automatic migrations. On line 11 in `manage.py`, we are creating a new `Migrate` object that takes in an `app` and a `db` object. Remember `db.Model`? This is where Flask-Migrate will look for changes once we give the command, and then migrate them to the database. Line 15 is where we define what the command will be. We are adding a `db` command that comes from the `MigrateCommand` object in Flask-Migrate. This will also give us extra options such as `db init`, `db migrate`, and `db upgrade`.

To perform the migrations (we have our initial models), cd into the folder that contains `manage.py`, and use the following commands in your terminal

* `python manage.py db init` - reads changes to db and creates a migrations folder
* `python manage.py db migrate` - applies migrations to database
* `python manage.py db upgrade` - commits all changes to the database

{% hint style="info" %}
If at any time you get an error, check your database URL. These can be a bit tricky to debug because everyone has different PostgreSQL install. A great majority of these errors will come down to a faulty database URL
{% endhint %}
