relation "notes_bundles" does not exist when it clearly does

You should not be running makemigrations on your server. You should run it locally, review and commit the migrations files, and copy them onto your server to run them.

But other than that, faking to 4 and then running migrate might indeed work.

1 Like

hey, I think we are really close, this will be the last question, I promise!
I faked back to 4 and then ran migrate,
I get the error:

django.db.utils.ProgrammingError: relation "notes_bundles" already exists

bundles was created in 0008_auto_…
I need to execute of the the migrations in it and basically not do the bundles part, so what if I remove migrations.CreateModel of bundles from it and then run it again?

this is 0008_auto_2022…:

class Migration(migrations.Migration):

    dependencies = [
        ('notes', '0007_notes_subject'),

    operations = [
            field=models.CharField(blank=True, choices=[('Anatomy', 'Anatomy'),....., ('Orthopaedics', 'Orthopaedics')], max_length=50, null=True),
                ('title', models.TextField(max_length=100)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
                ('notes', models.ManyToManyField(to='notes.Notes')),
                'ordering': ['-created_at'],

That might work! Do you have another migration that made the table? Can you work out how you got into this state? Is the table in the same state with the same columns and data types?

1 Like

I looked through all of them and apparently not!
I don’t know how I got here, I have been at this for a few days now, I think I must have accidentally done something weird that did this. I have been talking to anyone who could help me, on reddit and discord, finally now the only person i am listening to is you! so, I think that is where I must have faked something and then ran migrations and I don’t know, something happened. Sorry, its been a mess.

this is what I get using \d:

defaultdb=> \d notes_bundles
                      Table "public.notes_bundles"
   Column   |           Type           | Collation | Nullable | Default
 title      | text                     |           | not null |
 created_at | timestamp with time zone |           | not null |
 id         | uuid                     |           | not null |
 author_id  | integer                  |           | not null |
    "notes_bundles_pkey" PRIMARY KEY, btree (id)
    "notes_bundles_author_id_1edcc7ec" btree (author_id)
Foreign-key constraints:
    "notes_bundles_author_id_1ec_auth_user_id" FOREIGN KEY (author_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
Referenced by:
    TABLE "notes_bundles_notes" CONSTRAINT "notes_bundles_notes_bundles_id_b0a_fk_notes_bundles_id" FOREIGN KEY (bundles_id) REFERENCES notes_bundles(id) DEFERRABLE INITIALLY DEFERRED

I don’t see a notes field in the table, but i think that is a part of the Foreign-key constraints!

Here is the bundles model:

class Bundles(models.Model):

    author = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.TextField(null = False, blank = False, max_length = 100)
    notes = models.ManyToManyField(Notes)

    created_at = models.DateTimeField(auto_now_add=True)
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

    class Meta:
        ordering = ['-created_at']

Indeed - ManyToManyField does not generate a column on your model, but a separate table notes_bundles_notes. Look up many-to-many in SQL to understand this. The FK constraint binds the table for Notes to that table.

1 Like

On Linux you can see your shell history with the history command - that can help you figure out what you ran. Sometimes useful.

1 Like

dude, it worked! I am crying so hard right now, its been months since I last cried!

sorry for bothering you but I am so happy right now!
I literally have had trouble sleeping because of this and I have been stressing for days.
I can’t thank you enough, wow, I am so happy. Literally the happiest day I have had in soo long!
Thank you so much! I promise to pay it forward! I already try and do it on reddit as much as I can, but I promise to be a part of django forums as well. Thank you so much again!

PS. Silly question, but what made you wanna help me, I am just another idiot using tools you guys have masterfully crafted.

:+1: tears of joy I hope!

Good to hear!

I would recommend you cement your learning by writing up some notes on how to run Django migrations, what it means to fake them, etc. Write for yourself, or a blog!

This is what the Django community is about. I don’t have time to answer everyone but I answer a few posts I see in my inbox, when I have time. Your post was well written and detailed - that’s often the decider!


I did actually, I wrote a post on both of the django subreddits, and people have received it quite well. I just hope they don’t make the same mistakes as I did!

Thank you so much! Appreciate it a lot, Good night!

both? I know r/django, what’s the other?