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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:30:20+00:00 2026-05-25T03:30:20+00:00

When I try to query foreign keys using get(), I always get None values,

  • 0

When I try to query foreign keys using get(), I always get None values, even though I know they are set to 1 in the DB. Am I missing something here? Should I do something different to get the foreignkey values?

Here’s what the code looks like:

class Car_to_brand( models.Model ):
    brand_id = models.ForeignKey( Brand, db_column='brand_id' )
    ...

class Brand( models.Model ):
    (id is not defined here but it's the primary key)
    ...

print Car_to_brand.__dict__.get( brand_id )

That would give me {brand_id:None}, but it should be {brand_id:1}.

  • 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-25T03:30:20+00:00Added an answer on May 25, 2026 at 3:30 am

    The problem is that you have named your field brand_id and not brand. get(brand_id) is returning None, because there the key brand_id is not in the dictionary. If you print car.__dict__, you will see that it contains brand_id_id instead.

    However, it is highly unusual to access attributes using instance.__dict__.get(). Try the following instead:

    class Car( models.Model ):
        brand = models.ForeignKey(Brand) # don't need to set db_column, brand_id is the default
    
    
    car.brand_id # this is the id of the brand (e.g. 1) that this car is linked to 
    car.brand # this is the brand instance
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following HQL query to try and load a set of objects
When I try to run any update query in Access 2007, I get the
I'm experiencing extremely slow query execution when linking records on foreign keys. For instance
I'm using Doctrine 2 to try and do a query with an inner join.
I'm trying to use Subsonic 3.0 but with every query I try it gives
If I try to run this query in SQL Server 2005: SELECT 1 WHERE
I could try to post and explain the exact query I'm trying to run,
I use query string to access my pages. I try to make if anyone
I'll try to explain this better on another question. This is the query that
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error

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.