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

  • Home
  • SEARCH
  • 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 547103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:56:14+00:00 2026-05-13T10:56:14+00:00

I have an application which is in BETA mode. The model of this app

  • 0

I have an application which is in BETA mode. The model of this app has some classes with an explicit primary_key. As a consequence Django use the fields and doesn’t create an id automatically.

class Something(models.Model):
    name = models.CharField(max_length=64, primary_key=True)

I think that it was a bad idea (see unicode error when saving an object in django admin) and I would like to move back and have an id for every class of my model.

class Something(models.Model):
    name = models.CharField(max_length=64, db_index=True)

I’ve made the changes to my model (replace every primary_key=True by db_index=True) and I want to migrate the database with south.

Unfortunately, the migration fails with the following message:
ValueError: You cannot add a null=False column without a default value.

I am evaluating the different workarounds for this problem. Any suggestions?

Thanks for your help

  • 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-05-13T10:56:15+00:00Added an answer on May 13, 2026 at 10:56 am

    Agreed, your model is probably wrong.

    The formal primary key should always be a surrogate key. Never anything else. [Strong words. Been database designer since the 1980’s. Important lessoned learned is this: everything is changeable, even when the users swear on their mothers’ graves that the value cannot be changed is is truly a natural key that can be taken as primary. It isn’t primary. Only surrogates can be primary.]

    You’re doing open-heart surgery. Don’t mess with schema migration. You’re replacing the schema.

    1. Unload your data into JSON files. Use Django’s own internal django-admin.py tools for this. You should create one unload file for each that will be changing and each table that depends on a key which is being created. Separate files make this slightly easier to do.

    2. Drop the tables which you are going to change from the old schema.

      Tables which depend on these tables will have their FK’s changed; you can either
      update the rows in place or — it might be simpler — to delete and reinsert
      these rows, also.

    3. Create the new schema. This will only create the tables which are changing.

    4. Write scripts to read and reload the data with the new keys. These are short and very similar. Each script will use json.load() to read objects from the source file; you will then create your schema objects from the JSON tuple-line objects that were built for you. You can then insert them into the database.

      You have two cases.

      • Tables with PK’s change changed will be inserted and will get new PK’s. These must be “cascaded” to other tables to assure that the other table’s FK’s get changed also.

      • Tables with FK’s that change will have to locate the row in the foreign table and update their FK reference.

    Alternative.

    1. Rename all your old tables.

    2. Create the entire new schema.

    3. Write SQL to migrate all the data from old schema to new schema. This will have to cleverly reassign keys as it goes.

    4. Drop the renamed old tables.

     

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

Sidebar

Related Questions

I have an application which resides in ROOT. This application has a java class(in
I have an application which has a similar interface to Visual Studio, in that
I have an application which supports multiple types and versions of some devices. It
I have a beta application, which runs successfully on three Android powered devices: Google
I have developed a grails/groovy application for a legacy database which has user maintenance
I have a problem, I have an application which has a toolbar icon to
I have application which needs to use a dll (also written by me) which
I have an application which loads up c# source files dynamically and runs them
I have an application which needs to loop through all the lines in text
I have an application which i build using gcc on linux host for ARM

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.