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 9253795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:18:30+00:00 2026-06-18T11:18:30+00:00

I’ve been working on a sqlite3 database with a Django project. I’m moving the

  • 0

I’ve been working on a sqlite3 database with a Django project. I’m moving the project to the production environment where I use Postgres. I’ve used South, so I have all my migrations automated.

I’m running into the following error while trying to migrate the schema:

[05/Feb/2013 16:38:31] DEBUG [south:270] execute "ALTER TABLE "frontend_userprofile" ADD COLUMN "id" serial NULL PRIMARY KEY;" with params "[]"
FATAL ERROR - The following SQL query failed: ALTER TABLE "frontend_userprofile" ADD COLUMN "id" serial NULL PRIMARY KEY;
The error was: conflicting NULL/NOT NULL declarations for column "id" of table "frontend_userprofile"

[..]

django.db.utils.DatabaseError: conflicting NULL/NOT NULL declarations for column "id" of table "frontend_userprofile"

This is the relevant part of the migration file:

def forwards(self, orm):
    # Adding field 'UserProfile.id'
    db.add_column('frontend_userprofile', 'id',
                  self.gf('django.db.models.fields.AutoField')(default=None, primary_key=True, null=True),
                  keep_default=False)


    # Changing field 'UserProfile.user'
    db.alter_column('frontend_userprofile', 'user_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True, null=True))

[..]

    'frontend.userprofile': {
        'Meta': {'object_name': 'UserProfile'},
        'company': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['frontend.Company']", 'null': 'True'}),
        'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
        'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'null': 'True'})
    }

And of the model:

class UserProfile(models.Model):
    user    = models.OneToOneField(User, null=True, unique=True)
    company = models.ForeignKey(Company, null=True, default=None)

EDIT

As suggested by Jordan, you can’t have both a null primary key, so the following changes solve this problem:

    db.add_column('frontend_userprofile', 'id',
                  self.gf('django.db.models.fields.AutoField')(default=None, primary_key=True),
                  keep_default=False)


class UserProfile(models.Model):
    user    = models.OneToOneField(User, unique=True)
    company = models.ForeignKey(Company, null=True, default=None)

But I still have a problem finishing the migration:

DEBUG [south:270] execute "ALTER TABLE "frontend_userprofile" ADD COLUMN "id" serial NOT NULL PRIMARY KEY;" with params "[]"
FATAL ERROR - The following SQL query failed: ALTER TABLE "frontend_userprofile" ADD COLUMN "id" serial NOT NULL PRIMARY KEY;
The error was: multiple primary keys for table "frontend_userprofile" are not allowed

django.db.utils.DatabaseError: multiple primary keys for table "frontend_userprofile" are not allowed

I think the reason is that in a previous migration user_id has been set to primary key and now it’s trying to add id as primary key. Any help with this?

  • 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-18T11:18:31+00:00Added an answer on June 18, 2026 at 11:18 am

    You can’t have a NULL primary key, as far as i know. That would be bad.

    I recommend removing the part that says Null=True in that migration and trying again.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have been unable to fix a problem with Java Unicode and encoding. The
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am confused How to use looping for Json response Array in another Array.

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.