0

I have the following code:

mytable.to_sql(name='mytable', con=engine, index=True, if_exists='replace')

But it keeps throwing the following error:

'(1170, "BLOB/TEXT column 'index' used in key specification without a key length")'[SQL: CREATE INDEX ix_mytable_index ON mytable (index)]

I think I understand why the error happens but in the context for the code above I don't know how to specify the length. I can't change the underlying database since this code was handed down to me.

6
  • @snakecharmerb How would I do that? I know you could use params but what would the index length param look like? Commented Nov 24, 2020 at 19:49
  • Something like index_label='`index`(1000)' ? Commented Nov 24, 2020 at 20:08
  • Seems like a good idea but can't get the formatting to work. Still throws the same error. Commented Nov 24, 2020 at 20:21
  • Related: stackoverflow.com/q/34515714/2144390 - Your DataFrame appears to have a string index that is being translated into a TEXT (a.k.a. CLOB) column which is not suitable for a CREATE INDEX statement in MySQL (or most other databases). Commented Nov 24, 2020 at 23:30
  • @GordThompson Thank you this helped a lot. Anyway to stop pandas/dataframe from being a string? Commented Nov 25, 2020 at 1:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.