Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:28:03+00:00 2026-06-09T12:28:03+00:00

I am using Django 1.4 with PostgreSQL 9.1.4 what wrong with my models.py class

  • 0

I am using Django 1.4 with PostgreSQL 9.1.4

what wrong with my models.py

class UserProfile(models.Model):
    ROLES_TYPE = (
        ('Employee', 'Employee'),
        ('Employor', 'Employor'),
    )
    user = models.OneToOneField(User, related_name='Profile')
    role = models.CharField(max_length=15, choices=ROLES_TYPE)

class Student(models.Model):
    id = models.AutoField(db_column='studentid', primary_key=True)
    username = models.OneToOneField(UserProfile, related_name='Employee')
    first_name = models.CharField(db_column='fname', max_length=100,
                              null=True, blank=True)
    last_name = models.CharField(db_column='lname', max_length=100,
                             null=True, blank=True)

When I run ./manage.py syncdb , i got error

Creating tables ...
Creating table Student
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 102, in handle_noargs
    cursor.execute(statement)
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/home/jayapaldharmamani/Projects/jayapal/aplink/aplink_env/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
django.db.utils.DatabaseError: column "id" referenced in foreign key constraint does not exist

SQL Query after removing related names and ID field

CREATE TABLE “admin_userprofile” (

 "id" serial NOT NULL PRIMARY KEY,
       "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id") DEFERRABLE     INITIALLY DEFERRED,
        "role" varchar(15) NOT NULL
    );

CREATE TABLE “Student” (

       "id" serial NOT NULL PRIMARY KEY,
       "username_id" integer NOT NULL UNIQUE REFERENCES "admin_userprofile" ("id") DEFERRABLE INITIALLY DEFERRED
    );

Please help me.

Thanks & Regards,
Jayapal D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:28:04+00:00Added an answer on June 9, 2026 at 12:28 pm

    This is a problem generated by your database not django itself. Try to recreate your database schema (you can just remove all related columns and execute ./manage.py syncdb.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Django with a PostgreSQL (8.x) backend, I have a model where I need
I am using django-nonrel and django-mongodb-engine I have a Django model stored on PostgreSQL
I'm using Django 1.3 with Postgresql 8.4 and I've got models like the following
I'm using the standard (as opposed to NonRel) version of Django connected to PostgreSQL
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I am using Postgres as DBMS and Django. My model that defines the table
I am using Django and Postgresql as my DBMS. I wish to set a
Hi i am using django 1.2 .I my case i have few models which
Using sqlite3 and Django I want to change to PostgreSQL and keep all data
I have an existing PostgreSQL database that I'm using for a new Django site.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.