Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django migrate : doesn't create tables

After some errors, I dropped my database, deleted all my migration files (I left init.py). Now, when I run

python migrate.py makemigrations   // It creates migrations correctly python migrate.py migrate          // It outputs "app.0001_initial OK" 

But absolutely NO table (related to my app) is created. Only those related to django are. And in the migration table, my application migration is marked is done but no table have been created as I said, it's very displeasing.

Here is an excerpt my migration file :

# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2016-02-18 21:59 from __future__ import unicode_literals  import colorful.fields import django.core.validators from django.db import migrations, models import django.db.models.deletion   class Migration(migrations.Migration):      initial = True      dependencies = [     ]      operations = [         migrations.CreateModel(             name='Client',             fields=[                 ('id', models.AutoField(db_column='idtblclients', primary_key=True, serialize=False)),                 ('genre1', models.CharField(blank=True, max_length=10)),             ('prenom1', models.CharField(blank=True, max_length=45)),             ('nom1', models.CharField(blank=True, max_length=45)),             ('genre2', models.CharField(blank=True, max_length=10)),             ('prenom2', models.CharField(blank=True, max_length=45)),             ('nom2', models.CharField(blank=True, max_length=45)),             ('courriel', models.CharField(blank=True, max_length=45)),             ('langue', models.CharField(blank=True, max_length=1)),             ('numtel1', models.CharField(blank=True, db_column='NumTel1', max_length=20)),             ('numtel2', models.CharField(blank=True, db_column='NumTel2', max_length=20)),             ('numcivique', models.CharField(blank=True, db_column='NumCivique', max_length=15)),             ('rue', models.CharField(blank=True, db_column='Rue', max_length=45)),             ('ville', models.CharField(blank=True, db_column='Ville', max_length=45)),             ('codepostal', models.CharField(blank=True, db_column='CodePostal', max_length=45)),             ('timestamp', models.DateTimeField(blank=True, db_column='Timestamp', null=True)),             ('zone', models.CharField(blank=True, db_column='Zone', max_length=45)),         ],         options={             'db_table': 'tblclients',             'managed': False,         },     ), .... 

Do you have an idea how to fix it ?

like image 546
Adam Cherti Avatar asked Feb 18 '16 22:02

Adam Cherti


People also ask

Does Django migrate create database?

Since version 1.7, Django has come with built-in support for database migrations. In Django, database migrations usually go hand in hand with models: whenever you code up a new model, you also generate a migration to create the necessary table in the database.

What is difference between migrate and Makemigrations in Django?

makemigrations is responsible for packaging up your model changes into individual migration files - analogous to commits - and migrate is responsible for applying those to your database.

What does Django migrate do?

According to documentation, Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema.


1 Answers

python manage.py migrate --fake APPNAME zero 

This will make your migration to fake. Now you can run the migrate script

python manage.py migrate APPNAME 

Tables will be created and you solved your problem.. Cheers!!!

like image 62
Vignesh Avatar answered Sep 18 '22 12:09

Vignesh