Create initial revision from migration
See original GitHub issueHi, should the project document a way to make migrations file to make initial revision instead of running them manually on each server instance?
from __future__ import unicode_literals
from django.db import migrations
from django.core import management
def update_all_contenttypes():
from django.apps import apps
from django.contrib.contenttypes.management import create_contenttypes
for app_config in apps.get_app_configs():
create_contenttypes(app_config)
def get_models():
return (
'my_app.MyModel',
'my_app.MyModel2',
)
def init_reversion():
management.call_command(
'createinitialrevisions',
*get_models(),
comment="Initial revision.",
verbosity=1)
def clean_reversion():
management.call_command(
'deleterevisions',
*get_models(),
verbosity=1)
def forward(apps, schema_editor):
update_all_contenttypes()
init_reversion()
def backward(apps, schema_editor):
clean_reversion()
class Migration(migrations.Migration):
dependencies = [
('reversion', "0001_squashed_0004_auto_20160611_1202"),
('my_app', '0018_auto_20181230_0025'),
('contenttypes', '0002_remove_content_type_name'),
]
operations = [
migrations.RunPython(forward, backward),
]
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:16 (2 by maintainers)
Top Results From Across the Web
Code First Migrations with an existing database - EF6
Run the Update-Database command in Package Manager Console. This will apply the InitialCreate migration to the database. Since the actual ...
Read more >Developers - Create initial revision from migration - - Bountysource
Hi, should the project document a way to make migrations file to make initial revision instead of running them manually on each server...
Read more >Tutorial — Alembic 1.9.0 documentation
Create a Migration Script¶ ... The file contains some header information, identifiers for the current revision and a “downgrade” revision, an import of...
Read more >Creating "zero state" migration for existing db with sqlalchemy ...
alembic revision --autogenerate inspects the state of the connected database and the state of the target metadata and then creates a ...
Read more >Safely Test and Apply Changes to Your Database
2. Creating migrations ... In the first function we'll put the code we want to execute, for example creating a schema. In the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
if it make sense, a small tool may allow simpler migration:
which then would be used:
Sorry, I simply didn’t get the models part into my head. Had a discussion with a colleague and then it made click.
Reversion must use the model definitions from the Model class files at the time of executing the command, even if the migrations and current database state don’t reflect the state of that class yet.