Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

Changing TextField / Varchar length


5 Posts   785 Views


24 December 2011 at 5:07am Community Member, 3 Posts

Hello everyone,

I am not very familiar with SilverStripe but have been asked to do some maintenance on a site using SilverStripe for a client.

The client's SilverStripe site has a homepage (HomePage.php /, extends Page), that has a "Main" section, under which there is an editable TextField.

The problem is, whenever the client goes to add more than 50 characters to this TextField, everything after the 50th character gets truncated. The TextField itself does not have a $maxLength set, so it's possible to actually input more than 50 characters, but when they click "Save" and reload the page, only the first 50 characters remain.

I believe I've narrowed the problem down to the fact that the "static $db" array entry for this TextField is set to a "Varchar," and as I understand it if no length is specified for the Varchar then it takes a default length of 50 characters.

My problem is, if I change the $db array entry for this TextField to something else -- for example, "Varchar(200)" or "HTMLText", nothing appears to actually change. I upload the modified HomePage.php file, go into the CMS, and put more than 50 characters into the text field and click save, but it continues to be truncated to 50 characters regardless of what I changed the $db array entry to.

I suspect that the database itself needs to also be modified, but I have no idea where the data for this TextField would be stored in the database to modify it.

Does anyone have any ideas as to what I am missing, or which table (if any?) this data is stored in, or where I should look from here? Being unfamiliar with SilverStripe and how it stores data in the database, I am a little stumped. I would appreciate any help or direction you can give!

Thanks for your time,

Tim Snadden

24 December 2011 at 7:28am Community Member, 32 Posts

You are on the right track. To make the modifications in the database you need to run http://<yoursite>/dev/build


24 December 2011 at 7:44am Community Member, 3 Posts

Awesome, thank you, I will give that a shot.

Before I do though, can you just confirm for me what exactly this will do? Is it building only the internal database table that SilverStripe uses, or is it doing other things as well?

Also, is there an easy way to back up the current state (before running /dev/build) so that if something breaks I can restore it?

Once again, thank you very much for your help!

Happy holidays,

Tim Snadden

24 December 2011 at 8:10am (Last edited: 24 December 2011 8:11am), Community Member, 32 Posts

Unless you have an unusual setup all of the database tables will be being used by silverstripe and will have been created by running /dev/build which runs through your code and creates/modifies the database structure accordingly. In this case it will modify the column to have a 200 char limit or whatever you specified in $db.

What you are aiming to do is a very straightforward change but if you want to back up your db beforehand then there are a number of ways of doing it. Via terminal...

mysqldump -uYourUsername -pYourPassword yourdbname > yourdbname.sql

or Doing something similar with any other tool such as phpmyadmin or a desktop app. I'm assuming you are using mysql but it there are similar tools available for any other database.

I'm also assuming that you aren't doing this directly on your production web server! The truth is that for a minor change like this it's highly unlikely to cause any problems but it's a pretty bad habit to get into. Run this in your local dev environment first and confirm that it's all working as expected before pushing the code to production and running /dev/build. To do this when the server is in 'live' mode you'll need to be logged in.


24 December 2011 at 8:48am Community Member, 3 Posts

Thank you Tim!

This is just a confirmation post that running /dev/build?flush=1 was successful in changing the database and now the TextField is not getting cut off at 50 characters anymore. Thanks again for your quick and articulate responses!

Unfortunately our company neither designed the site nor runs its servers, and apparently there is indeed only a single production environment on which the CMS is installed; there is no development environment! (Unbelievable, I know.) Hence the question about backing everything up beforehand which also went without a hitch.

Thank you again, and enjoy your holiday! : )