Search code examples
sqlmysqldefault-constraint

Unable to set a URL as Default value in MySQL


I am using phpMYAdmin to set a URL as a Default Value to a Field of a Table in MySQL database, but of no luck.

The URL is like this one:

http://www.kaboodle.com/hi/img/c/0/0/b2/9/AAAADMEBXEUAAAAAALKWPw.jpg

Here is the Table field structure:

{varchar(255), utf8_general_ci, Not Null}

Solution

  • It's unclear what is wrong, but this will create a DEFAULT constraint for an existing table using an ALTER TABLE statement to to set the URL value if one is not provided when a record is inserted:

    ALTER TABLE your_table 
    ALTER the_column SET DEFAULT 'http://www.kaboodle.com/hi/img/c/0/0/b2/9/AAAADMEBXEUAAAAAALKWPw.jpg'