SQLite3 in Python 2.7 Rejecting Foreign Key Insert
rosuav at gmail.com
Sun Nov 23 06:41:35 CET 2014
On Sun, Nov 23, 2014 at 3:58 PM, Michael Torrie <torriem at gmail.com> wrote:
> On 11/22/2014 08:54 PM, llanitedave wrote:
> Well that DID make a difference! I used the %r marker, and the logger
> line gave me back:
>> "INFO:Related borehole_id is u'testbh3', of_borehole is 'testbh3'"
>> So it looks like I need to change my foreign key string to a unicode
>> string. I'll be working on that...
> Or manually encode it to a UTF-8 byte string (just call .encode() on
> it). Sqlite probably only knows about UTF-8 when it comes to unicode.
Since it was a byte string sent to the database and a Unicode string
coming back, the solution would be to .decode() the byte string.
However, I doubt that's the issue; that's being done for you
implicitly by the lower-level connections. Also, in Python 2:
>>> u'testbh3' == 'testbh3'
So that's not your primary problem. You could try that, but I doubt
it'll solve anything for you.
Are you able to switch to Python 3, though? If you are, Unicode issues
tend to be a lot easier to resolve there.
More information about the Python-list