Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!
#1 Tiago said
Great tips. Thanks Miguel.
#2 James said
Hi Miguel, I followed your flask-mega-tutorial to develop an internal employee directory app. But I'm having an issue with SQLIte and MySQL when it comes to storing output from a WYSIWYG editor. While developing I used SQLite like you recommended in your tutorial. I used the Text() type to store the HTML data from the editor, which worked fine for me. But once I deployed to our server and over to MySQL I started getting "Data too long for column" errors for any output longer than a few sentences.
Do you know if there are any significant differences between SQLite and MySQL that would cause this issue?
#3 Miguel Grinberg said
@James: SQLite is not strict with lengths, but MySQL is. Are you sure this is for a column of type Text? My guess is that this problem is for a String or similar column where you either didn't specify a size or the size is small compared to the content you are writing to the column.
#4 James said
@Miguel: No It's definitely set to Text
about_me = db.Column(db.Text)
It is possible that I need to set a length for Text as well?
#5 James said
@Miguel: So an quick update. It looks like I'm running up against some 140 character limit in my strings for Text. If I go passed that I get the "Data is too long" error.
#6 Miguel Grinberg said
@James: are you sure the model agrees with what's in the database? Please check the database schema using a MySQL admin tool. I think you must have had the 140 character limit in the past, or in a migration file. If you changed from 140 to unlimited that needs a new database migration.
#7 James said
@Miguel: Just an update on this, I did as you suggested and noticed that the column was set as VARCHAR(140). I was able to switch the column over to LONGTEXT and this cleared up my issue. Thanks for the help!
If you want to learn the ins and outs of relational database programming with Python and SQLAlchemy, consider my SQLAlchemy 2 In Practice book, available on Amazon.
Welcome to my blog!
I'm a software engineer and technical writer, currently living in Drogheda, Ireland.
You can also find me on Twitter, Mastodon, Github, LinkedIn, YouTube, Facebook and Patreon.
Thank you for visiting!