3π
β
It turns out when you change a DateField
to a DateTimeField
south will just change it for you so it wonβt conflict.
For example I ran:
python manage.py schemamigration --auto hotel
and got this output:
~ Changed field start_date on hotel.Event
~ Changed field end_date on hotel.Event
Created 0018_auto__chg_field_event_start_date__chg_field_event_end_date.py. You can now apply this migration with: ./manage.py migrate hotel
Although i would advide backing up the database before making any changes.
π€JDavies
0π
You can easily do that with south:
python manage.py schemamigration --auto appname
The whole column will start at midnight (eg, 2013-09-26
-> 2013-09-26 00:00:00
). To change the hour, edit your migration, and after the column has been changed, put:
import datetime
from django.db.models import F
# ... Automatically created db.alter_column
if not db.dry_run: # needed whenever making data changes
# This will add 9 hours to *all* records
orm['appname.ModelName'].objects.all().update(start_date=F('start_date') + datetime.timedelta(hours=9))
As for the end_date
, it will already start at midnight, but if you want to set it to 23:59:59
, you may also add datetime.timedelta(hours=23, minutes=59, seconds=59)
or simply datetime.timedelta(seconds=86399)
, which is less readable.
π€augustomen
- [Django]-Why does a Python script work from the CLI, but not when called from a cron job?
- [Django]-Graphene-Django nested filters (relay)
- [Django]-Docker: The command returned a non-zero code: 137
Source:stackexchange.com