I have a rather annoying issue when trying to send my merge to my automated tests on circle CI.
Just for the context, I've inherited a project where the authors are no longer working at my current work.
I'm working on django and I've done a merge, from my local dev branch to my local master branch. The merge went well. However, when starting the django server through a manage.py runserver
, it gives me the warning Your project may not work properly until you apply the migrations for app(s)[...]
.
When doing the manage.py migrate
, I'm running into the first issue:
1- django.db.utils.ProgrammingError: relation "cms_disclaimerpanel" already exists
I fix the issue by manually editing the migration file, commenting the following lines
# migrations.CreateModel(
# name='DisclaimerPanel',
# fields=[
# ('abstractpanel_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='cms.AbstractPanel')),
# ('title', models.CharField(blank=True, max_length=1024, verbose_name='title')),
# ('show_title', models.BooleanField(default=True, verbose_name='show title')),
# ('subtitle', models.TextField(blank=True, verbose_name='content')),
# ('show_subtitle', models.BooleanField(default=True, verbose_name='show subtitle')),
# ('alignment', models.CharField(choices=[('left', 'left'), ('center', 'center')], default='center', max_length=10, verbose_name='text alignment')),
# ('button', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cms.Link')),
# ],
# options={
# 'verbose_name': 'Disclaimer Panel',
# },
# bases=('cms.abstractpanel',),
# )
Then the second issue happened, while carrying my manage.py migrate
2 - ProgrammingError: column "http_request_lang" of relation "cms_dynamicsettings" does not exist
I fix the issue by manually editing the migration file, commenting the following lines
#operations = [
# migrations.RemoveField(
# model_name='dynamicsettings',
# name='http_request_lang',
# ),
#]
The manage.py
was able to run entirely. Then I ran manage.py makemigrations
and it gives me this last file
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('cms', '0088_merge_20190411_1655'),
]
operations = [
migrations.CreateModel(
name='DisclaimerPanel',
fields=[
('abstractpanel_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='cms.AbstractPanel')),
('title', models.CharField(blank=True, max_length=1024, verbose_name='title')),
('show_title', models.BooleanField(default=True, verbose_name='show title')),
('subtitle', models.TextField(blank=True, verbose_name='content')),
('show_subtitle', models.BooleanField(default=True, verbose_name='show subtitle')),
('alignment', models.CharField(choices=[('left', 'left'), ('center', 'center')], default='center', max_length=10, verbose_name='text alignment')),
('button', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cms.Link')),
],
options={
'verbose_name': 'Disclaimer Panel',
},
bases=('cms.abstractpanel',),
),
migrations.RemoveField(
model_name='dynamicsettings',
name='http_request_lang',
),
]
With the changes above, I can runmanage.py runserver
.
I'm then adding these 3 files to my merged branch and create a distant repository for my branch.
Each new repository created is run through the unit test and there lies the issue as it does not take into account my three newly commited files.
It gives me the following error, the same error as in the point 2 (see above).
ERROR: relation "cms_dynamicsettings" does not exist at character 1508
Using my dev environnement as a template, my guess would be that circle ci is replicating the same issue I've encountered and that I manually fixed.
The questions are the following:
Is there a way to drop my model
cms_disclaimer
before it runs through that damn migration file? If yes, how?Is there a way to not take into account the migration file and tell it not to drop the column
http_request_lang
My last question is why the
manage.py makemigrations
does not see the changes in the database?
One more information:
The database was built with the branch master. I checkout on another branch based on master , merged my dev branch into master and then do manage.py migrate
.
Any info will be more than welcome as I'm loosing my sanity.
Thanks.