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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:25:40+00:00 2026-06-17T12:25:40+00:00

I have the following models: class Look(Base): __tablename__ = looks id = Column(Integer, primary_key=True)

  • 0

I have the following models:

class Look(Base):
  __tablename__ = "looks"
  id = Column(Integer, primary_key=True)
  url = Column(String, nullable=False, unique=True)

class Similarity(Base):
  __tablename__ = 'similarities'
  __table_args__ = (UniqueConstraint('look_id_small', 'look_id_big'),)
  id = Column(Integer, primary_key=True)
  look_id_small = Column(Integer, ForeignKey('looks.id'), nullable=False)
  look_id_big = Column(Integer, ForeignKey('looks.id'), nullable=False)

When I am running this code:

try:
  with session.begin_nested():
    similarity = Similarity()
    similarity.look_id_small, similarity.look_id_big = look_id1, look_id2
    session.add(similarity)
    session.commit()
except Exception, e:
  logging.error(e)
  print "look_id1: %s, look_id2: %s" % (look_id1, look_id2)

This is the error I am getting:

2013-01-19 04:55:42,974 ERROR Foreign key associated with column 'similarities.look_id_small' could not find table 'looks' with which to generate a foreign key to target column 'id'
look_id1: 217137, look_id2: 283579

so I tried looking for these values in pgsql and they do exist!

giordano=# SELECT * FROM looks WHERE id = 217137 or id = 283579;
   id   |                      url                      | title | image_url | 
--------+-----------------------------------------------+-------+-----------+
 217137 | http://foo.com                                |       |           |     
 283579 | http://baz.com                                |       |           |
(2 rows)

I have spent the whole night trying to figure this out.

Some clues:

  1. I am only getting these errors on certain values.
  2. I don’t think having double foreignkeys on the same table will result in an issue.

Anyone?

EDIT:

giordano=# \d+ looks 
                                              Table "public.looks"
    Column     |       Type        |                     Modifiers                      | Storage  | Description 
---------------+-------------------+----------------------------------------------------+----------+-------------
 id            | integer           | not null default nextval('looks_id_seq'::regclass) | plain    | 
 url           | character varying | not null                                           | extended | 
Indexes:
    "looks_pkey" PRIMARY KEY, btree (id)
    "looks_url_key" UNIQUE CONSTRAINT, btree (url)
Referenced by:
    TABLE "similarities" CONSTRAINT "similarities_look_id_big_fkey" FOREIGN KEY (look_id_big) REFERENCES looks(id)
    TABLE "similarities" CONSTRAINT "similarities_look_id_small_fkey" FOREIGN KEY (look_id_small) REFERENCES looks(id)
Has OIDs: no

giordano=# \d+ similarities
                                             Table "public.similarities"
    Column     |       Type       |                         Modifiers                         | Storage | Description 
---------------+------------------+-----------------------------------------------------------+---------+-------------
 id            | integer          | not null default nextval('similarities_id_seq'::regclass) | plain   | 
 look_id_small | integer          | not null                                                  | plain   | 
 look_id_big   | integer          | not null                                                  | plain   | 
Indexes:
    "similarities_pkey" PRIMARY KEY, btree (id)
    "similarities_look_id_small_look_id_big_key" UNIQUE CONSTRAINT, btree (look_id_small, look_id_big)
Foreign-key constraints:
    "similarities_look_id_big_fkey" FOREIGN KEY (look_id_big) REFERENCES looks(id)
    "similarities_look_id_small_fkey" FOREIGN KEY (look_id_small) REFERENCES looks(id)
Has OIDs: no

EDIT

After turning on my postgresql statements, this is what I am seeing:

LOG:  statement: BEGIN
LOG:  statement: select version()
LOG:  statement: select current_schema()
LOG:  statement: show transaction isolation level
LOG:  statement: SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
LOG:  statement: SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
LOG:  statement: ROLLBACK
LOG:  statement: BEGIN
LOG:  statement: DECLARE "c_10dfc08d0_1L" CURSOR WITHOUT HOLD FOR SELECT feedbacks.id AS feedbacks_id, feedbacks.user_id AS feedbacks_user_id, feedbacks.look_id AS feedbacks_look_id 
    FROM feedbacks 
     LIMIT 500
LOG:  statement: FETCH FORWARD 1 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 5 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 10 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 20 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 50 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 100 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 250 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 500 FROM "c_10dfc08d0_1L"
LOG:  statement: FETCH FORWARD 1000 FROM "c_10dfc08d0_1L"
LOG:  statement: CLOSE "c_10dfc08d0_1L"
LOG:  statement: ROLLBACK
LOG:  unexpected EOF on client connection

I am not seeing any “INSERTS”. Why?

  • 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-17T12:25:42+00:00Added an answer on June 17, 2026 at 12:25 pm

    Turns out using ForeignKey(Look.id) did the trick!!

    According to argonholm from #sqllachemy:

    18:25 agronholm: I would have to guess that the syntax for text-form table references is not what you expected 18:26 agronholm: maybe ForeignKey(‘Look.id’) would also work?

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

Sidebar

Related Questions

I have the following models: class ProjectUser(models.Model): categories = models.ManyToManyField('UserCategory', blank=True, null=True) user_id =
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
I have the following models: class FieldEntryValue < ActiveRecord::Base belongs_to :field_entry end and class
I have the following models: class Mark < ActiveRecord::Base validates_presence_of :user validates_presence_of :page belongs_to
I have some models and have views code that look like the following class
I have the following simple models: class Event < ActiveRecord::Base has_many :participations has_many :users,
I have the following models set up: class Player < ActiveRecord::Base has_many :game_players has_many
I have the following table: class Feedback(Base): __tablename__ = 'feedbacks' __table_args__ = (UniqueConstraint('user_id', 'look_id'),)
I have the following models: class Foo has_and_belongs_to_many :bars end class Bar has_and_belongs_to_many :foos
I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =

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.