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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:59:14+00:00 2026-06-05T12:59:14+00:00

When I add a book model to the database, and then look at the

  • 0

When I add a book model to the database, and then look at the book table in SQL Database Browser, it shows the id field as being blank.

It’s strange because I have 1000 items in the table. I don’t know what happened, because ~390 of them have their ID populated. The others have their id blank.

Shouldn’t the id field be essentially the primary key? How could it have been populated in some cases and not other cases.

Note1: In the past I have manually deleted records — not sure if that might be an issue.
Note2: When I print "newbook id:", repr(newbook.id), the id is different than the primary key seen in SQL Database Browser.

This is what I see:

enter image description here

The relevant code is below:

Model:

class Books (models.Model):
    bookname=models.CharField(_('bookname'), max_length=255)
    publisher=models.CharField(_('publisher'), max_length=255)
    description=models.TextField(_('description'), blank=True)
    coverart = models.ImageField(upload_to="art", blank=True, null=True)
    source=models.TextField(blank=True) #source of where it came from
    last_updated=models.DateTimeField(_('added'), default=datetime.now)
    category_id=models.ManyToManyField(Category, related_name='cat')
    model = models.ManyToManyField ('model', related_name = 'model')
    shortdesc=models.TextField(_('description'), blank=True)
    url = models.TextField(_('url'), blank=True)
    uid = models.IntegerField()`

Code that saves a book:

try: 
    exists = Books.objects.get(bookname=bookname)
except Books.DoesNotExist:
    print "book does not exist -- adding now"
    newbook=Books(bookname=bookname, uid = uid, source='Mysourceofbooks',     publisher=publisher, description = description, shortdesc=shortdesc, url = url)
    newbook.save()
    for cat in category_ids:
        newbook.category_id.add(cat)
else:
    print "log: we found the book in the DB already"`
  • 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-05T12:59:15+00:00Added an answer on June 5, 2026 at 12:59 pm

    As per the discussion in chat: the id column in the Book table somehow managed to lose its status as a PRIMARY KEY. Set that back and you should be good to go.

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

Sidebar

Related Questions

I'm trying to add a timestamp field to my model for indexing by Sunspot/Solr.
I was trying the next code without success HTML <a id=addBookButton href=javascript:showForm('addBookButton','add-book','activateAddBookForm'); class=addA><span>Add Book</span></a>
For instance if I do something like: Criteria c = session.createCriteria(Book.class) .add(Expression.ge(release,reDate); .add(Expression.ge(price,price); .addOrder(
I'm using Google Book Search API to add missings bits and pieces to my
I want to add a shortcut like I type :open_my_document, it become :e /var/book/document.txt.
I have a C#.NET Outlook 2007 add-in that has to access the address book
I have 3 tables: Book, Section and Content. I want to add many-to-many relation
I'm Using Camick's ListTableModel and RowTableModel from here http://tips4java.wordpress.com/2009/03/12/table-from-database/ However, the JTable is not
Here is example how my array should look like: $library = array( 'book' =>
I have a model book with a one to many relation with authors. I

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.