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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:17:09+00:00 2026-05-30T02:17:09+00:00

I’m using an existing database made by a third party with sqlalchemy. However, I’m

  • 0

I’m using an existing database made by a third party with sqlalchemy. However, I’m having trouble as the tables do not have primar keys, and what’s worse, they have duplicate elements for each row, so I can’t pick an existing column as primary key. The tables have two columns: both have non-unique values.

I tried to monkey-patch the table as per http://www.blog.pythonlibrary.org/2010/09/10/sqlalchemy-connecting-to-pre-existing-databases/ but apparently this does not work (see below)

My current code is (MirnaTable is my mapped class, basically just a skeleton with nothing else)

connection = create_engine("sqlite:///targets.sqlite")
metadata = MetaData(bind=connection)
db_table = Table("miranda", metadata,
                 Column("id", Integer, primary_key=True),
                 autoload=True)
mapper(MirnaTable, db_table)
Session = sessionmaker(connection)
session = Session()

Then I try for example issuing

all_records = session.query(MirnaTable).all()

And I get

sqlalchemy.exc.OperationalError: (OperationalError) no such column: miranda.id 
u'SELECT miranda.gene_id AS miranda_gene_id, miranda."mature_miRNA" AS
"miranda_mature_miRNA", miranda.id AS miranda_id \nFROM miranda' ()

So of course the id column isn’t found. Any ideas on what I’m doing wrong? Thanks in advance.

EDIT: As requested, here is an example from the table (retrieved directly from sqlite):

gene  mature_miRNA 
---- -------------
80205  hsa-miR-200c 
80205  hsa-miR-200c 
9693  hsa-miR-200c 
9693  hsa-miR-200c 
9881  hsa-miR-200c 
9710  hsa-miR-200c 
9750  hsa-miR-200c 
  • 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-30T02:17:11+00:00Added an answer on May 30, 2026 at 2:17 am

    You’ve misinterpreted the post you refer to. You have to choose an existing column and define it as primary. It’s also possible to setup composite primary key by putting them all in definition. In your case I think a gene has several mature microRNA, so the primary key should probably consist of (gene_id, mature_miRNA) pair. Since there is no more fields in the table, there is no need in autoload=True flag.

    db_table = Table("miranda", metadata,
                     Column("gene_id", Integer, primary_key=True),
                     Column("mature_miRNA", Integer, primary_key=True))
    

    I don’t know the types of fields in your table, so change them appropriately if they are not integer.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have a reasonable size flat file database of text documents mostly saved in
I have thousands of HTML files to process using Groovy/Java and I need to
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.