Brad's Blog

Published: 2009-05-06

Data Truncated Errors

Python django mysql web

I recently ran into some of the Data truncated for column ... errors in my django apps. After a little digging, I've discovered that my particular problem lie in the structure of the underlying MySQL tables. Particularly with varchar columns. I have a model that contains a FileField:class MyModel(models.Model): file = models.FileField(upload_to="files/%Y/%m/%d")Note that the MySQL table generated by this model will look something like the following:+-------------+--------------+------+-----+---------------------+----------------+| Field | Type | Null | Key | Default ...

Published: 2009-04-01

How to Set up a Foreign Key Constraint in MySQL

Programming mysql web

The default storage engine in MySQL (MyISAM) does not support Foreign Key constraints. If you want to use Foreign Keys in Mysql, you need to use InnoDB.The following is a simple example that illustrates Foreign Key constraints, we'll create tables to store information about Authors and their Books. The Foreign key will link a book to an Author. Note, that in MySQL we need to use the InnoDB storage engine to support Foreign Key Constraints.First, we need ...

Published: 2007-01-05

Migrating PHP scripts to MySQL from PostgreSQL

Programming mysql php postgresql

I've recently had to work on a project where I needed toconvert some very basic PHP code thataccessed a postgresqldatabase so that it would work with mysql. For the most part, this has beenfairly simple thanks to rpl. Many of PHP'sdatabase functions have very similar names, so I simply use rpl toconvert the existing code. Here's a simple bashscript that I put together to convert some of my postgresqlfunctions to mysql: #!/bin/bash if [ ! -n "$1" ] then ...