0

This problem is driving me nuts - I can't spot what's going on so I was hoping that someone would be able to point out what I'm missing here.

I've got two sample models, FootballClub, FootballPitch, as defined below.

class FootballClub(models.Model)
  name = models.CharField(max_length=100)

  class Meta:
    ordering = ['name']

  def __unicode__(self):
    return self.name
class FootballPitch(models.Model):
  name = models.CharField(max_length=100)
  owning_club = models.ForeignKey(FootballClub)

I've made a modification to the FootballPitch class, more specifically the owning_club field, to add null=True to it, so the class now looks like this;

class FootballPitch(models.Model):
  name = models.CharField(max_length=100)
  owning_club = models.ForeignKey(FootballClub, null=True)

(I don't need to manage this model through a form so I don't care that blank=True is not set).

I have also run makemigrations and migrate on this model.

When trying to list out all instances of FootballPitch that have owning_club set to null (using FootballPitch.objects.filter(owning_club__isnull=True)) I get the following error;

Programming Error: relation "footballclub_footballpitch" does not exist LINE 1: ...d", "footballclub_footballpitch"."name",FROM "footballclub_f...

Anyone have any ideas what is going wrong? (Django 1.8.18 and Python 2.7 and postgres 9.8 for reference)

Thanks in advance!

Edit: Due to request added migrations code here instead of in reply to comment requesting it;

./manage.py --list outputs the following; [X] 0001_initial [X] 0002_auto_20191009_1409

The migration contains # -- coding: utf-8 -- from future import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('football', '0001_initial'), ] operations = [ migrations.AlterField( model_name='footballpitch', name='owning_club', field=models.ForeignKey(to='football.FootballClub', null=True), ), ]

Edit++ to include initial migration

from __future__ import unicode_literals

from django.db import migrations, models
import django.utils.timezone
import django_extensions.db.fields


class Migration(migrations.Migration):

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='FootballClub',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('name', models.CharField(max_length=100)),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='FootballPitch',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('name', models.CharField(max_length=100)),
                ('owning_club', models.ForeignKey(to='football.FootballClub')),
            ],
        ),
    ]```

  • Is that all your `FootballPitch` code or do you have more? Also, did you declare the app in your INSTALLED_APPS? – Higor Rossato Oct 09 '19 at 14:55
  • That's all for my FootballPitch code - I've just got the app name in INSTALLED_APPS, `INSTALLED_APPS = ['**OTHER APPS**', 'football']` – just_ben1996 Oct 09 '19 at 14:58
  • Have you tried to run `makemigrations` and `migrate` after input your app into `INSTALLED_APPS`? – Higor Rossato Oct 09 '19 at 15:01
  • Please show the contents of the migrations and the output of `manage.py migrate --list`. Note that's an old command for Django 1.8. Django 1.8.X has been end of life since April 2018). – Alasdair Oct 09 '19 at 15:06
  • @HigorRossato Yes this is an existing system so the app was already installed in the project before these changes/migrations were created and run – just_ben1996 Oct 09 '19 at 15:13
  • @Alasdair ./manage.py --list outputs the following; ``` [X] 0001_initial [X] 0002_auto_20191009_1409 ``` The migration contains ``` # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('football', '0001_initial'), ] operations = [ migrations.AlterField( model_name='footballpitch', name='owning_club', field=models.ForeignKey(to='football.FootballClub', null=True), ), ] ``` – just_ben1996 Oct 09 '19 at 15:14
  • @Alasdair I've updated the original reply there with the contents – just_ben1996 Oct 09 '19 at 15:17
  • Please don't post code in the comments. [Edit] your question. – Alasdair Oct 09 '19 at 15:20
  • @Alasdair I've done that just now – just_ben1996 Oct 09 '19 at 15:25
  • You've only shown one of the migrations. – Alasdair Oct 09 '19 at 15:28
  • @Alasdair Again, just done that now for you – just_ben1996 Oct 09 '19 at 15:35
  • The first migration should have created the `Football` pitch table in the database, but the error *Programming Error: relation "footballclub_footballpitch" does not exist* suggests it didn't. Does the `FootballClub` table exist in the db? You could check with `print(FootballClub.objects.all())`. – Alasdair Oct 09 '19 at 15:42
  • If the football pitch table does not exist, then it looks as if the initial migration did not run at all. Perhaps you used `--fake`. For the models and migrations you posted, it should be safe to [rerun the migrations](https://stackoverflow.com/questions/31953587/rerun-a-django-data-migration) (since you are rerunning the initial migration, fake to `zero`) – Alasdair Oct 09 '19 at 15:46

0 Answers0