Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-03-01 Thread Julien Cigar
On Sun, Mar 01, 2015 at 10:57:31AM -0800, Javier Pajuelo wrote: Thanks. I followed the same principle, but had to change the set_attr to first check if the attribute was an instance of datetime, because my db accepted string of a datetime and not datetime. I have a question, what does

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-03-01 Thread Javier Pajuelo
Now, that I have inspected the MySQL instance each time it runs through the scraper I noticed that jobs and candidates do not duplicate , but the event table duplicates. I am changing my updateevent method as you suggested, but I am having trouble dealing with foreign keys. Here's my update

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-03-01 Thread Julien Cigar
On Sun, Mar 01, 2015 at 08:06:31AM -0800, Javier Pajuelo wrote: Thanks for the help, but in the code below it shows that setattr expects 3 arguments but got two instead. What is this code really doing? I know that my candidate fields are : name, id, link, timeStamp. Help. Thanks On

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-03-01 Thread Javier Pajuelo
Thanks. I followed the same principle, but had to change the set_attr to first check if the attribute was an instance of datetime, because my db accepted string of a datetime and not datetime. I have a question, what does *first()* mean in this context? for _candidate_data in candidates:

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-18 Thread Chris Withers
On 17/02/2015 18:43, Javier Pajuelo wrote: The weird part is that I just checked my candidates table and I see no duplicates. However, during the generation of a report that ties candidates, jobs, and events, I get duplicate candidates. My suspicion is that it's your code which does the

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Javier Pajuelo
Just to give you an idea of the code: Basically the code scrapes some websites and gets info into objects. Client class with client info, event class with event info, and so on. There are foreign keys to tie event and client classes. Sometimes even when I scrape the web and try to upload

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Javier Pajuelo
Hi Chris, Thanks for trying to help. The code is as follow: #== # CompassCandidate() #== class CompassCandidate(Base): '''

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Jonathan Vanasco
The simplest way using your code would be: for _candidate_data in candidates: _existing = session.query(CompassCandidate).filter(CompassCandidate.id == _candidate_data.id).first() if not _existing: # add the new item session.add(_candidate_data) else: # translate the attributes from the new item

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Jonathan Vanasco
This looks to be your problem: id = Column(String(64), primary_key=True) `id` is a primary key, which means it must be unique. But you're not setting it to a unique value. Most people will use a Serial column for this. -- You received this message because you are subscribed to the

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Javier Pajuelo
Could you give an example of using a serial column? I believe that whatever comes into the first argument of column is a unique value from another DB. Also, I thought that the person who wrote the code missed to use relationships between candidates and jobs. e.g.:class User(Base): #

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Jonathan Vanasco
A serial would usually be an integer that is tied to a sequence (postgres, oracle) or auto_increment (mysql). I see in your example that you have a unicode string -- `ORaE9+aCdP0` If that is coming from another db, then you've already migrated that candidate. you'll should do a search for

Re: [sqlalchemy] SQL Alchemy on Insert to DB

2015-02-17 Thread Chris Withers
What does the code look like that generates 'candidates'? Chris On 17/02/2015 00:48, Javier Pajuelo wrote: I get the following error: | sqlalchemy.exc.IntegrityError: (IntegrityError) column id is not unique u'INSERT INTO candidates (id, timeStamp, name, link) VALUES (?, ?, ?, ?)'

[sqlalchemy] SQL Alchemy on Insert to DB

2015-02-16 Thread Javier Pajuelo
I get the following error: sqlalchemy.exc.IntegrityError: (IntegrityError) column id is not unique u'INSERT INTO candidates (id, timeStamp, name, link) VALUES (?, ?, ?, ?)' (u'ORaE9+aCdP0', '2015-02-16 18: 19:58.00', u'Kunal Sethi',