Q:

Migrating django models in Postgres/PostGIS not reflecting

I successfully imported my Geojson data using ogr2ogr to PostGIS.
I run the following command: python manage.py inspectdb
class Route(models.Model):
   ogc_fid = models.AutoField(primary_key=True)
   distance = models.FloatField(blank=True, null=True)
   route_type = models.CharField(max_length=-1, blank=True, null=True)
   route_long = models.CharField(max_length=-1, blank=True, null=True)
   route_name = models.CharField(max_length=-1, blank=True, null=True)
   agency_id = models.ForeignKey(max_length=-1, blank=True, null=True)
   route_id = models.CharField(max_length=-1, blank=True, null=True)
   route_url = models.CharField(max_length=-1, blank=True, null=True)
   route_desc = models.CharField(max_length=500, blank=True, null=True)
   duration = models.FloatField(blank=True, null=True)
   shape_id = models.IntegerField(blank=True, null=True)
   route_tcolor = models.CharField(max_length=-1, blank=True, null=True)
   route_color = models.CharField(max_length=-1, blank=True, null=True)
   wkb_geometry = models.LineStringField(blank=True, null=True)

class Meta:
    managed = False
    db_table = 'network_route'

Of course, I had to modify the max_length to a positive integer and set manage to True so I did.
I also added an additional column, created_at and updated_at.
Resulting to the following final model:
class Route(models.Model):
   ogc_fid = models.AutoField(primary_key=True)
   distance = models.FloatField(blank=True, null=True)
   route_type = models.CharField(max_length=100, blank=True, null=True)
   route_long = models.CharField(max_length=200, blank=True, null=True)
   route_name = models.CharField(max_length=100, blank=True, null=True)
   agency_id = models.ForeignKey(Agency, on_delete=models.CASCADE)
   route_id = models.CharField(max_length=100, blank=True, null=True)
   route_url = models.CharField(max_length=300, blank=True, null=True)
   route_desc = models.CharField(max_length=500, blank=True, null=True)
   duration = models.FloatField(blank=True, null=True)
   shape_id = models.IntegerField(blank=True, null=True)
   route_tcolor = models.CharField(max_length=100, blank=True, null=True)
   route_color = models.CharField(max_length=100, blank=True, null=True)
   wkb_geometry = models.LineStringField(blank=True, null=True)

   created_at = models.DateTimeField(default=timezone.now(),editable=False)
   updated_at = models.DateTimeField(blank=True, null=True)

   objects = models.GeoManager()

class Meta:
    managed = True
    db_table = 'network_route'

def save(self, *args, **kwargs):
    #On save, update timestamps
    if not self.id:
        self.created_at = timezone.now()
    self.updated_at = timezone.now()
    return super(Route, self).save(*args, **kwargs)

def __str__(self):
    return self.route_id

I run: makemigrations [appname] and it only detects the changes in Meta - Change Meta options on route
How can I add additional changes in the model such as the created_at and updated_at be caught by the migration?
Am I doing something wrong?

A:

The problem must have occurred from that line in your legacy code: managed = False. There are some options though on how to solve your problem:

The easy (clean slate) way:
Since you can rebuild your database and you don't have anything that you can't live without, erase everything and do it over. 

Erase everything except __init__.py in your migrations folder.
Erase your database and remake it.
./manage.py makemigrations.
./manage.py migrate.

Well, you will lose everything but this is the "clean slate" approach.
The (probably) better way:
Open up your last migration (the one made with the makemigrations command) and write the rest by hand:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import django.utils.timezone
from django.db import migrations, models

class Migration(migrations.Migration):
    dependencies = [
        ('your_app', 'your_previous_migration'),
    ]

    operations = [
        # That takes care of you Meta changes 
        migrations.AlterModelOptions(
            name='route',
            options={
                'managed': True, 
                'table': 'network_route', 
            },
        ),
        # That will add the created_at field
        migrations.AddField(
            model_name='route',
            name='created_at',
            field=models.DateTimeField(
                default=django.utils.timezone.now,
                editable=False
            ),
        ),
        # That will add the updated_at field
        migrations.AddField(
            model_name='route',
            name='updated_at',
            field=models.DateTimeField(blank=True, null=True),
   ]

Now you can try ./manage.py migrate with that migration which should do the trick!

