Solved

MySQL Default Value

Posted on 2011-03-21
2
339 Views
Last Modified: 2012-05-11
When I try to enter a default value for a TEXT column in my MySQL database it will not let me. Is it possible to have a default value in a MySQL TEXT field?

I'm trying to write some PHP code that enters data in the MySQL databse & not being able to set a default field in the MySQL TEXT field is causeing some issues....

FYI...I am using PhP MyAdmin to try to set it up
0
Comment
Question by:wantabe2
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35179867
From the reference:
http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html
BLOB and TEXT columns cannot be assigned a default value.

so, you might try VARCHAR data type instead, if it's ok for that:
http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html

or, remove the NULL constraint, so that the field does allow NULLS.

note: a TEXT means very large text, which shall normally allow null ...
0
 
LVL 2

Expert Comment

by:ramkihardy
ID: 35179889
simple....
before passing values to the databse...
Check the textfiled is null....
if its is null..then pass the default value
else
pass the textfield value to the database...
Regards
Ramki
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now