You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.rst
+17-5Lines changed: 17 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,26 +49,38 @@ You can then generate an initial migration::
49
49
50
50
$ flask db migrate -m "Initial migration."
51
51
52
-
The migration script needs to be reviewed and edited, as Alembic currently does not detect every change you make to your models. In particular, Alembic is currently unable to detect table name changes, column name changes, or anonymously named constraints. A detailed summary of limitations can be found in the `Alembic autogenerate documentation <http://alembic.zzzcomputing.com/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect>`_. Once finalized, the migration script also needs to be added to version control.
52
+
The migration script needs to be reviewed and edited, as Alembic is not always able to detect every change you make to your models. In particular, Alembic is currently unable to detect table name changes, column name changes, or anonymously named constraints. A detailed summary of limitations can be found in the `Alembic autogenerate documentation <https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect>`_. Once finalized, the migration script also needs to be added to version control.
53
53
54
-
Then you can apply the migration to the database::
54
+
Then you can apply the changes described by the migration script to your database::
55
55
56
56
$ flask db upgrade
57
57
58
-
Then each time the database models change repeat the ``migrate`` and ``upgrade`` commands.
58
+
Each time the database models change, repeat the ``migrate`` and ``upgrade`` commands.
59
59
60
60
To sync the database in another system just refresh the `migrations` folder from source control and run the ``upgrade`` command.
61
61
62
62
To see all the commands that are available run this command::
63
63
64
64
$ flask db --help
65
65
66
-
Note that the application script must be set in the ``FLASK_APP`` environment variable for all the above commands to work, as required by the ``flask`` command line script.
66
+
Note that the application script must be set in the ``FLASK_APP`` environment variable for all the above commands to work, as required by the ``flask`` command.
67
+
68
+
Alembic Configuration Options
69
+
-----------------------------
70
+
71
+
Starting with version 4.0, Flask-Migrate automatically enables the following options that are disabled by default in Alembic:
72
+
73
+
- ``compare_type=True``: This option configures the automatic migration generation subsystem to detect column type changes.
74
+
- ``render_as_batch=True``: This option generates migration scripts using `batch mode <https://alembic.sqlalchemy.org/en/latest/batch.html>`_, an operational mode that works around limitations of many ``ALTER`` commands in the SQLite database by implementing a "move and copy" workflow. Enabling this mode should make no difference when working with other databases.
75
+
76
+
To manually configure these or `other Alembic options <https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure>`_, pass them as keyword arguments to the ``Migrate`` constructor. Example::
77
+
78
+
migrate = Migrate(app, db, render_as_batch=False)
67
79
68
80
Configuration Callbacks
69
81
-----------------------
70
82
71
-
Sometimes applications need to dynamically insert their own settings into the Alembic configuration. A function decorated with the ``configure`` callback will be invoked after the configuration is read, and before it is used. The function can modify the configuration object, or replace it with a different one.
83
+
Sometimes applications need to dynamically insert their own settings into the Alembic configuration. A function decorated with the ``configure`` callback will be invoked after the configuration is read, and before it is applied. The function can modify the configuration object, or replace it with a different one.
0 commit comments