Arjuna
Arjuna

Reputation: 69

Django 1.8.5 Migrations not migrating to Postgres database at all

I am having a strange problem. I am creating a simple table. The initial migration 0001 looks like:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Customer',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('company_name', models.CharField(default=b'', unique=True, max_length=100)),
                ('address1', models.CharField(default=b'', max_length=200)),
                ('address2', models.CharField(default=b'', max_length=200, blank=True)),
                ('city', models.CharField(default=b'', max_length=200)),
                ('state', models.CharField(default=b'', max_length=100)),
                ('pincode', models.IntegerField(default=b'')),
                ('landline', models.CharField(default=b'', max_length=15, blank=True)),
                ('email', models.EmailField(default=b'', max_length=254, blank=True)),
                ('website', models.CharField(default=b'', max_length=100, blank=True)),
                ('contact1_first_name', models.CharField(default=b'', max_length=100)),
                ('contact1_last_name', models.CharField(default=b'', max_length=100)),
                ('contact1_mobile', models.CharField(default=b'', max_length=15, blank=True)),
                ('contact1_email', models.EmailField(default=b'', max_length=254, blank=True)),
                ('contact2_first_name', models.CharField(default=b'', max_length=100, blank=True)),
                ('contact2_last_name', models.CharField(default=b'', max_length=100, blank=True)),
                ('contact2_mobile', models.CharField(default=b'', max_length=15, blank=True)),
                ('contact2_email', models.EmailField(default=b'', max_length=254, blank=True)),
            ],
        ),
    ]

I did makemigrations, i did migrate, i did syncdb. I get no errors, and absolutely no table is made in postgres sql. I had to make the table manually by doing sqlmigrate and posting the code into PGADMIN3. That did the trick and created the table.

However the whole point of using Django is that changes to the Model should be migrated over to the database and I should not have to change the model and the database separately, manually.

I have searched online and I dont see anyone else having a similar problem. Its a very basic issue, there are no errors and no changes to the database. What could the problem be?

Upvotes: 2

Views: 1665

Answers (1)

Arjuna
Arjuna

Reputation: 69

When things are not working with the model and you want to start from scratch,what worked with me was

  1. Make changes to your model to get it just right.
  2. Delete all the migrations, by deleting the migrations folder in your app
  3. In the database look for the migrations table (I used pgadmin3 as a front end for postgres sql) and delete rows that mention your app name
  4. Run makemigrations appname, migrate and syncdb

And you have a fresh database exactly corresponding to your model, minus all the crud with migrations and all the small changes you made along the way, that you may not need to track.

Upvotes: 1

Related Questions