﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25832	Migrating a django-cms.PlaceholderField fails when using Postgres	Jon Ribbens	nobody	"It seems to me that 'makemigrations' creating broken migrations is a bug. The django-cms people say it is a django bug not a django-cms bug, hence my ticket here (see https://github.com/divio/django-cms/issues/4789 ).

{{{
$ pip install djangocms-installer psycopg2
$ djangocms -sqp . -d postgresql://test:test@localhost/test my_demo
$ python manage.py startapp testapp
}}}
Add testapp as penultimate entry in my_demo/settings.py:INSTALLED_APPS.
Edit testapp/models.py:
{{{#!python
from django.db import models
class TestModel(models.Model):
    description = models.TextField(""Description"")
}}}
{{{
$ python manage.py makemigrations testapp
$ python manage.py migrate
}}}
Edit testapp/models.py:
{{{#!python
from django.db import models
from cms.models.fields import PlaceholderField
class TestModel(models.Model):
    description = PlaceholderField(""Description"")
}}}
{{{
$ python manage.py makemigrations testapp
$ python manage.py migrate
...
Running migrations:
  Rendering model states... DONE
  Applying testapp.0002_auto_20151129_1448...Traceback (most recent call last):
  File ""test/env/lib/python3.4/site-packages/django/db/backends/utils.py"", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: column ""description_id"" cannot be cast automatically to type integer
HINT:  You might need to specify ""USING description_id::integer"".
}}}
This only happens with Postgres (or rather, it doesn't happen with sqlite, i.e. if you remove the -d from the djangocms invocation above). It only happens if the column is being changed in one migration, if it's split into two migrations the first of which deletes the column and the second of which creates it, there is no issue.

I was originally actually getting ""ValueError: Related model 'cms.Placeholder' cannot be resolved"", but I cannot reproduce that so easily since I already fixed it in my project - see mailing list thread https://groups.google.com/forum/#!topic/django-cms/tIT3g0gCpwc."	Bug	closed	Database layer (models, ORM)	1.8	Normal	invalid			Unreviewed	0	0	0	0	0	0
