[sqlalchemy] Re: trouble when second time insert value

2017-05-21 Thread R0R0N0A
solved it by checking before inserting 
use session.query().filter().count()

now everything runs ok .
many thanks 

On Sunday, May 21, 2017 at 11:13:37 PM UTC+8, bb1898 wrote:
>
> Am 21.05.2017 um 13:45 schrieb R0R0N0A: 
> > it's true that I insert the same record every time I run the code 
> > But it's unique , right ? it shouldn't insert to the table right ? 
> > 
> Quite right - and obviously it didn't. The database system must tell you 
> that it couldn't insert the record. And of course any software between 
> you and the DBMS must relay that message. And that's exactly what 
> happened, as far as I can see. 
>
> > My purpose is loop the code and see if any new record updated , if so , 
> > insert into the table . 
> > 
>
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: trouble when second time insert value

2017-05-21 Thread Sibylle Koczian

Am 21.05.2017 um 13:45 schrieb R0R0N0A:

it's true that I insert the same record every time I run the code
But it's unique , right ? it shouldn't insert to the table right ?

Quite right - and obviously it didn't. The database system must tell you 
that it couldn't insert the record. And of course any software between 
you and the DBMS must relay that message. And that's exactly what 
happened, as far as I can see.



My purpose is loop the code and see if any new record updated , if so ,
insert into the table .




--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: trouble when second time insert value

2017-05-21 Thread R0R0N0A
I followed this blog 
```https://www.dataquest.io/blog/apartment-finding-slackbot/```

` How I built a Slack bot to help me find an apartment in San Francisco 
` 

it says `that set the parameter as unique , in case of duplicates` 

and I did exactly the same 



On Sunday, May 21, 2017 at 7:45:09 PM UTC+8, R0R0N0A wrote:
>
> it's true that I insert the same record every time I run the code 
> But it's unique , right ? it shouldn't insert to the table right ?
>
> My purpose is loop the code and see if any new record updated , if so , 
> insert into the table .
>
> any where I did wrong ?
> thanks 
>
> On Sunday, May 21, 2017 at 6:50:03 PM UTC+8, bb1898 wrote:
>>
>> Am 21.05.2017 um 12:28 schrieb R0R0N0A: 
>> > I have a table and some keys inside it 
>> > have two unique key 
>> > when i first run the code it runs okay 
>> > but when I sencond time run it 
>> > it says a unique key constrains 
>> > 
>> > 
>> > here's the matter that I need to loop the code to query some new 
>> updates 
>> > and insert to database 
>> > I dont know why except the first time . why other time I run it , it 
>> got 
>> > error 
>> > 
>> > many thanks ! 
>> > 
>> > ``` 
>> > __tablename__ = 'listings' 
>> > 
>> > id = Column(Integer,primary_key=True,autoincrement=True) 
>> > link = Column(String,unique=True) 
>> > title = Column(String) 
>> > img = Column(String,unique=True) 
>> > name = Column(String) 
>> > ``` 
>> > 
>> > error code : 
>> > ``` 
>> > UNIQUE constraint failed: listings.img [SQL: 'INSERT INTO listings 
>> > (link, title, img, name) VALUES (?, ?, ?, ?)'] 
>> > ``` 
>> > 
>> ... 
>>
>> > 
>> > To post example code, please provide an MCVE: Minimal, Complete, and 
>> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
>> > description. 
>>
>> Your example isn't complete or verifiable, but I'll guess: do you 
>> perhaps try to insert the same record every time you run the code? You 
>> don't show the values you're inserting, so guessing is all we can do. 
>>
>> How do you connect to your database? Did you try to use "echo=True" in 
>> that call? That could tell you which query is sent to the database and 
>> what values are used. 
>>
>> HTH 
>> Sibylle 
>>
>>
>>
>>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: trouble when second time insert value

2017-05-21 Thread R0R0N0A
it's true that I insert the same record every time I run the code 
But it's unique , right ? it shouldn't insert to the table right ?

My purpose is loop the code and see if any new record updated , if so , 
insert into the table .

any where I did wrong ?
thanks 

On Sunday, May 21, 2017 at 6:50:03 PM UTC+8, bb1898 wrote:
>
> Am 21.05.2017 um 12:28 schrieb R0R0N0A: 
> > I have a table and some keys inside it 
> > have two unique key 
> > when i first run the code it runs okay 
> > but when I sencond time run it 
> > it says a unique key constrains 
> > 
> > 
> > here's the matter that I need to loop the code to query some new updates 
> > and insert to database 
> > I dont know why except the first time . why other time I run it , it got 
> > error 
> > 
> > many thanks ! 
> > 
> > ``` 
> > __tablename__ = 'listings' 
> > 
> > id = Column(Integer,primary_key=True,autoincrement=True) 
> > link = Column(String,unique=True) 
> > title = Column(String) 
> > img = Column(String,unique=True) 
> > name = Column(String) 
> > ``` 
> > 
> > error code : 
> > ``` 
> > UNIQUE constraint failed: listings.img [SQL: 'INSERT INTO listings 
> > (link, title, img, name) VALUES (?, ?, ?, ?)'] 
> > ``` 
> > 
> ... 
>
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
>
> Your example isn't complete or verifiable, but I'll guess: do you 
> perhaps try to insert the same record every time you run the code? You 
> don't show the values you're inserting, so guessing is all we can do. 
>
> How do you connect to your database? Did you try to use "echo=True" in 
> that call? That could tell you which query is sent to the database and 
> what values are used. 
>
> HTH 
> Sibylle 
>
>
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: trouble when second time insert value

2017-05-21 Thread Sibylle Koczian

Am 21.05.2017 um 12:28 schrieb R0R0N0A:

I have a table and some keys inside it
have two unique key
when i first run the code it runs okay
but when I sencond time run it
it says a unique key constrains


here's the matter that I need to loop the code to query some new updates
and insert to database
I dont know why except the first time . why other time I run it , it got
error

many thanks !

```
__tablename__ = 'listings'

id = Column(Integer,primary_key=True,autoincrement=True)
link = Column(String,unique=True)
title = Column(String)
img = Column(String,unique=True)
name = Column(String)
```

error code :
```
UNIQUE constraint failed: listings.img [SQL: 'INSERT INTO listings
(link, title, img, name) VALUES (?, ?, ?, ?)']
```


...



To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.


Your example isn't complete or verifiable, but I'll guess: do you 
perhaps try to insert the same record every time you run the code? You 
don't show the values you're inserting, so guessing is all we can do.


How do you connect to your database? Did you try to use "echo=True" in 
that call? That could tell you which query is sent to the database and 
what values are used.


HTH
Sibylle



--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.