Postgres Database Error: relation does not exist

橙三吉。 提交于 2019-12-01 06:54:55

问题


I am fixing some problems with a legacy system and have run into a snag that I am surprised was not caught sooner. I am running Django 1.3 and using postgres 9.1.3 in running this application. The system is a validation system for users to use the rest of the system. It uses part of the Django users interface, but mostly it has it's own 'Users'.

My problem comes along when I try and give a user their account questions (similar to if you forget a password to a website). When I try to do that it throws this error:

Database Error at admin/password/user

relation "password_user_answered_questions_id_s" does not exist
LINE 1: SELECT CURRVAL('"password_user_quest...
              ^

Does anyone know what might cause this error? I have tried resetting the db (didn't think it would do anything but just wanted to be sure) and have also poked around in the db using phppgadmin and found that everything else is getting stored correctly except this one. It is using a ManyToMany field when assigning it so that a user can have multiple questions and a question can be used by multiple users.


回答1:


The reason is most likely that the

relation "password_user_answered_questions_id_s" does not exist

Just like the error message informs us. Are you aware of how PostgreSQL handles identifiers?

Also, sequences are usually named *_seq. Letters missing from the end?


About maximum length of identifiers - I quote the manual from the link above:

The system uses no more than NAMEDATALEN-1 bytes of an identifier; longer names can be written in commands, but they will be truncated. By default, NAMEDATALEN is 64 so the maximum identifier length is 63 bytes. If this limit is problematic, it can be raised by changing the NAMEDATALEN constant in src/include/pg_config_manual.h.

Bold emphasis mine. Seems like you should shorten your identifiers a bit.




回答2:


The problem is you haven't synced your DB, I guess. Please execute these commands:

  1. python manage.py makemigrations myappname
  2. python manage.py migrate myappname


来源:https://stackoverflow.com/questions/10354756/postgres-database-error-relation-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!