I have a django blog project via PythonAnywhere using PostGres, and have recently tried to push my changes (mainly implementing Django-MPTT) to my models to my production server via git.
I have ran migrations etc, but when I load the site, I got a server error 500. The error logs look a bit like this :
"/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute#012 return self.cursor.execute(sql, params)#012django.db.utils.ProgrammingError: column posts_category.lft does not exist#012LINE 1: ...gory"."parent_id", "posts_category"."parentSlug", "posts_cat...#012
The original error said category.name doesn't exist, which is a new field I added to my Category database (well, actually I renamed it). I added this column to the database in my production environment via psql :
(ALTER TABLE ADD COLUMN name varchar(200)
and then I got another column does not exist, namely the one above. This comes from making use of Django-MPTT recently, and I've realised I'm out of my depth with creating these columns which are not visible in my models.
My question is, have I done this wrong? I understand that I am trying to impose a changed MVT structure onto my existing blog posts data, but is there an easier way to get this fixed? This error will keep re-appearing but I don't want to do a botched job of choosing the datatype for the new columns. I scanned through my traceback and added the columns as per the error (noobinfo: I just applied varchar(200) to all):
posts_category.name
posts_post.category_id
posts_category.parent_id
posts_category.lft
posts_category.right
posts_category.level
I've added all of these columns so far, but now I'm getting:
"/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute#012 return self.cursor.execute(sql, params)#012django.db.utils.ProgrammingError: operator does not exist: character varying = integer#012LINE 1: ...osts_category" WHERE "posts_category"."parent_id" = (SELECT ...#012 ^#012HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I am now way out of my depth, and need your help!
Many thanks. David
EDIT
Following @solarisstorm advice :
I have now created a manual migration to add one field so far, the 'name' column. That error has now disappeared. The next one is :
column posts_category.parent_id does not exist
When I added the following to a new migration file :
operations = [
migrations.AddField(
model_name="category",
name="parent_id",
field=("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='PARENT_ID')),
),
]
I get the following error when using the migrate command :
File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/db/mig rations/operations/fields.py", line 75, in state_forwards delay = not field.is_relation AttributeError: 'tuple' object has no attribute 'is_relation'
I tried add is_relation='parent' to my field in the migration file, but this doesn't work. "Got unexpected keyword argument".
Many thanks.