telethon-session-sqlalchemy icon indicating copy to clipboard operation
telethon-session-sqlalchemy copied to clipboard

Primary key can't be text

Open damienkilgannon opened this issue 7 years ago • 1 comments

In order to address the following issue ...

sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (1170, "BLOB/TEXT column 'md5_digest' used in key specification without a key length") [SQL: '\nCREATE TABLE sent_files (\n\tsession_id VARCHAR(255) NOT NULL, \n\tmd5_digest BLOB NOT NULL, \n\tfile_size INTEGER NOT NULL, \n\ttype INTEGER NOT NULL, \n\tid BIGINT, \n\thash BIGINT, \n\tPRIMARY KEY (session_id, md5_digest, file_size, type)\n)\n\n'] (Background on this error at: http://sqlalche.me/e/e3q8)

damienkilgannon avatar Nov 20 '18 15:11 damienkilgannon

Thanks for the pull request!

I don't think the field can be made non-primary safely as the other fields don't uniquely identify files, but it can probably be a smaller column type since it's just a md5 hash. Maybe use BLOB on SQLite and BINARY(32) on other DBMSes or even just a LargeBinary(32)? Another option is to just drop the primary key completely

tulir avatar Nov 25 '18 18:11 tulir