I know we can increased the size of varchar using this command:
alter table TABLE_NAME modify COLUMN_NAME VARCHAR(1024) NOT NULL;
Suppose I have 10 tables and each table has one common column which is varchar and its name is “title”. Is there any query which I can execute regardless of table names and it will update the size of this field in each and every table?
Scenario:
Actually I have used a BaseModel which is Abstract and many of my models inherit themselves from that. Now I have Update the title length to 500 in my Base Model. Doing a Manage.py syncdb will not going to reflect these changes. So that is why I need above query.
class TitleAndSlugModel(models.Model):
title = models.CharField(max_length=500)
slug = models.SlugField(null=True, blank=True, help_text="The part of the title that is used in the url")
I wouldn’t do it via SQL directly… instead, change it in all your models (e.g. max_length=1024) and do a migration using South –> http://south.readthedocs.org/en/0.7.6/tutorial/part1.html
South == awsomeness
also, you might need to convert your app to use South –> http://south.readthedocs.org/en/0.7.6/convertinganapp.html#converting-an-app
etc. etc.