1

I have just deployed a django application for the first time using MySQL as the database. In development, I am using sqlite3 and south for migrations.

I suppose I am to use python manage.py syncdb then python manage.py migrate to initialize the database. However, when I run python manage.py syncdb for the first time in production, I get the following error:

DatabaseError: relation "utils_message" does not exist LINE 1: ...sage"."message_type", "utils_message"."text" FROM "utils_mes...

What could I be missing? Could it be a cyclic dependency of some sort?

My INSTALLED_APPs setting looks like this:

INSTALLED_APPS = (
     'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions',
     'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles',
     'south', 'django.contrib.admin',  'mainapp', 'employerprofile', 'applicantprofile',
     'companies', 'postings', 'utils', 'searchjobs', 'comments', 'projectapp',
     'cart',  'applications', 'packages', 'feedback', 'cvbank', 'staffpostings',
     'logs',
     # Uncomment the next line to enable admin documentation:                       
     # 'django.contrib.admindocs',                                                     
)
krm
  • 773
  • 2
  • 5
  • 12
  • Have you created the database in MySQL (named as in settings.py `DATABASES['default']['NAME']) ? – stalk May 12 '13 at 09:51
  • Yes, the database exists, and the django db user has all rights to it. – krm May 12 '13 at 10:02
  • 2
    your database contain old table schema ? Django can't update schema (ie: add new field on existing model already synced is impossible with ./manage syncdb), it can only create it from scratch (you could use South to migrate and update old schema) – 0xBAADF00D May 12 '13 at 10:22
  • There's no existing schema. The database is empty. I want to initialize the db for the first time. – krm May 12 '13 at 10:33
  • It is a bad practice to use different databases in development and in production. Could you please show your `INSTALLED_APPS` and models? – alecxe May 12 '13 at 11:51
  • @alecxe Seems I'm learning the hard way :( – krm May 12 '13 at 16:35

1 Answers1

0

Solved the problem. It was caused by a dependency among the models.

I did a grep on Message and discovered that a field in a model in the postings app depended on an instance of the Message model in the utils app as its default value, ie:

from utils.models import Message
...
default_message = Message.objects.get(message_type='application-receipt-message').text
...
class Posting(models.Model):
    ....
    receipt_message = models.TextField(default=default_message)
    ...

So I changed the default_message to an empty string, did python manage.py syncdb followed by python manage.py migrate, and didn't experience any more problems.

krm
  • 773
  • 2
  • 5
  • 12