Closed plusflora closed 7 months ago
When you look in your actual database on neon, does the dream table have an owner_id column? Also, what happens when you attempt to make migrations? (and are these migrations meant to add the owner_id column?)
I can't see the neon database, I'm not the owner of it. I'll hit up Jacob. But in the meantime - these are supposed to add the owner_id and then retroactively assign the dreams currently in the database. if deleting the current dreams from the database would fix this I can do that.
Can you send the error message you get when you run the makemigrations command?
The last change I did has makemigrations working - but migrate doesn't. this is the error that I got from that.
Running migrations: Applying main_app.0007_dream_owner...Traceback (most recent call last): File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.NotNullViolation: column "owner_id" of relation "main_app_dream" contains null values
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/vbouq/sei/projects/Project3-DreamHues/Project3-DreamHues/Project3DreamHues/manage.py", line 22, in
Try changing your default from None to 1
We're talking about the model right? So like this?
class Dream(models.Model):
# all that other code
# Adds an owner field to link the dream to a user
owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name='dreams', default=1)
I did that and I still got this Operations to perform: Apply all migrations: admin, auth, contenttypes, main_app, sessions Running migrations: Applying main_app.0007_dream_owner...Traceback (most recent call last): File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.NotNullViolation: column "owner_id" of relation "main_app_dream" contains null values
It let me makemigration but it won't let me migrate.
Easiest thing to do would be to drop that table for dreams and then run the migrations. The problem is that the newly added owner field would be missing values for older entries in your db. Adding a default doesn't always work, as the default usually just applies that to future entries.
My recommendation: Go into the admin portal and copy all of the dreams you've added so far and paste them into a note or something, that way it'll be easy to add them back once the table is updated.
Describe the bug A clear and concise description of what the bug is. In attempting to assign dreams to specific users, I'm now getting broken pages and am unable to makemigrations/migrate to attempt to fix this.
What is the problem you are trying to solve? Assigning dreams to users (models.py under the Dream/DreamForm models)
Expected behavior A clear and concise description of what you expected to happen. the page correctly showing.
What is the actual behavior? A clear and concise description of what actually happened.
Post any code you think might be relevant (one fenced block per file)
What is your best guess as to the source of the problem? having dreams in the database without owners.
What things have you already tried to solve the problem? I've tried to retroactively assign them a user but that doesn't want to work.
Additional context Add any other context about the problem here. I've kinda looped around a few times back to the same point.
Paste a link to your repository here https://github.com/plusflora/Project3-DreamHues/tree/vince