question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation on adding default pages in a data migration

See original GitHub issue

It would be great if there was an example somewhere of creating pages via a data migration.

Here’s my attempt point97/marco-portal2/initial_data/migrations/0001_create_ocean_stories_container.py

It is deficient in that the URL doesn’t get set. As a workaround I set live = False, so that the URL gets set on publish. There may be other data consistency issues which I haven’t bumped into yet.

Improvements to this approach?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gasmancommented, Sep 30, 2016

Idle thought - could we perhaps provide some helper functions for doing tree operations, that live outside of the Page class and are thus usable with the ‘barebones’ Page model that’s available inside migrations? Something like:

from wagtail.wagtailcore.utils import tree_ops

def insert_pages(apps, schema_editor):
    Page = apps.get_model('wagtailcore.Page')
    homepage = Page.objects.get(url_path='/home/')
    new_page = Page(title='new page')
    tree_ops.add_child(homepage, new_page)

As far as I recall, most of the heavy lifting in django-treebeard happens outside the mixin in dedicated classes like AddChildOperation, so we could probably piggyback on those.

1reaction
mx-mothcommented, Sep 28, 2016

@kurtrwall For the reasons you have listed, we do not create pages in migrations. Instead we have management commands - one for creating the base site skeleton of required pages, and another that makes some random test pages. As they are management commands, they have full access to the proper models.

We try and keep the site skeleton management command idempotent with respect to existing data, so that running it multiple times as the project grows will have the same effect as running it on a new database. This does take extra work compared to migrations, and kind of duplicates the work of a migration, which is unfortunate.

I’ve not come up with a better solution. If anyone has a better idea, I would also love to hear it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Migration - Default Rules - IFS Documentation
Rule ID Procedure Name Description ADDOBJID MIGRATE% REPLICATION Create extra detail for OBJID BUILDTRIGGERIF REPLICATION Build IF‑statement for updateable columns CALLEXTPROC CREATE_OUTPUT_FILE Call external procedure after...
Read more >
Performing the data migration - BMC Documentation
The first data migration moves all of the data that has been added or changed since you made the production backup. The second...
Read more >
Data Migration Roadmap Guidance - Federal Student Aid
The following external documents provide either governance or guidance for this document. DOCUMENT ID. DOCUMENT TITLE. DOCUMENT. VERSION. Front ...
Read more >
Migrate portal configuration - Power Apps | Microsoft Learn
We will soon migrate and merge the Power Apps portals documentation with Power Pages documentation. Portal development involves several ...
Read more >
Data migration - Ibexa Developer Documentation
3.3, the ezmigrationbundle package has been removed to mitigate this issue. It is recommended that you use the default ibexa/migrations package to migrate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found