Write own migration files

linkaiyi
Follow

Write own migration files

# Generated by Django 2.1.14 on 2020-04-13 06:17

from django.db import migrations, models
from datetime import datetime


def datetime_to_date(apps, schema_editor):
    # We can't import the Person model directly as it may be a newer
    # version than this migration expects. We use the historical version.
    Employee = apps.get_model("organization", "Employee")
    for employee in Employee.objects.all():
        # convert a date to a date time on the product instance
        if employee.start:
            employee.start = datetime.date(employee.start)
        if employee.end:
            employee.end = datetime.date(employee.end)
        employee.save()


class Migration(migrations.Migration):

    dependencies = [
        ('organization', '0027_auto_20200413_0815'),
    ]

    operations = [
        migrations.AlterField(
            model_name='employee',
            name='end',
            field=models.DateField(blank=True, null=True, verbose_name='end'),
        ),
        migrations.AlterField(
            model_name='employee',
            name='start',
            field=models.DateField(blank=True, null=True, verbose_name='start'),
        ),
        migrations.RunPython(datetime_to_date)
    ]
Object has 0 attachments

Was this article helpful?

This article is viewed 11 times!

Recent Viewed Articles

0 Comments

Leave a Comment

Support