I have quite a specific problem, with django-admin.py not creating tables for model in the application directory. I have created a PostgreSQL database, and user, then granted this user all Privileges on the database, then included this database in settings.py. The relevant section of settings.py looks like below:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'crawler',
'USER': 'austinpowers',
'PASSWORD': '****',
'HOST': 'localhost',
'PORT': ''
}
}
Django is able to access this database, as manage.py dbshell works well.
Now i want Django to create tables based on following models.py file of application "crawler":
from django.db import models
class Files(models.Model):
id = models.IntegerField(primary_key=True, blank=False, null=False)
filename = models.TextField(blank=True, null=True)
status = models.IntegerField(blank=True, null=True)
def __unicode__(self):
return self.filename
class Meta:
verbose_name = 'File'
verbose_name_plural = 'Files'
class IpLog(models.Model):
id = models.IntegerField(primary_key=True, blank=False, null=False)
ip = models.TextField(blank=True, null=True)
time_changed = models.TextField(blank=True, null=True)
def __unicode__(self):
return self.time_changed
class Meta:
verbose_name = 'IP Log'
verbose_name_plural = 'IP Logs'
class Jobs(models.Model):
id = models.IntegerField(primary_key=True, blank=False, null=False)
run_no = models.IntegerField(blank=True, null=True)
shop = models.TextField(blank=True, null=True)
pzn = models.TextField(blank=True, null=True)
status = models.IntegerField(blank=True, null=True)
def __unicode__(self):
return self.shop + ": " + self.pzn
class Meta:
verbose_name_plural = 'Jobs'
verbose_name = 'Job'
So I make sure "migrations" folder in "crawler" app subdirectory is empty, the database is empty, and then call:
python manage.py makemigrations
.. what leads to following output:
No changes detected
So I want to force Django to create initial migrations for application "crawler" by running:
python manage.py makemigrations crawler --empty
... what outputs:
Migrations for 'crawler':
crawler/migrations/0001_initial.py:
However, when I want to see the contents of the migration file /crawler/migrations/0001_initial.py, I get an empty migration file:
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2016-12-15 13:25
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
]
operations = [
]
What suggests, that Django does not want for some reason, to create corresponding tables for models in models.py.
Indeed, when i call ...
python manage.py migrate
... I get the following output:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, crawler, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying crawler.0001_initial... OK
And the tables for my models are not present in the database.
Do you know, how can I force Django to create the tables? Django version used is 1.10.4
Thanks in advance for your help.
crawlerapp in the list ofINSTALLED_APPS?python manage.py migrateto apply migration changes to db.