Alter tables to replace Byteflow

Recently, I replaced this site’s Byteflow with latest one. Unfortunately, the former version that I used was distributed last October. Since a couple of Models were modified last November, I had to alter database tables to update my Byteflow .

All I had to do is described in The Django Book, Chapter 5, “Making Changes to a Database Schema”.

First, I compared each create table command by running manage.py sqlall [each app] command on each version. As Byteflow dev site announces, Site link field and related index(es) were added to blog.Post and blogroll.Link model classes. After copying down the database for work , I altered these tables’ schema by running sql commands as follows. I’m using MySQL.

For blog.Post model’s table:

ALTER TABLE `blog_post` ADD `site_id` INT( 11 ) NOT NULL DEFAULT '1' AFTER `id` ;

Note that default value ‘1’ is my site id on my django_site table. I had to set it for existing records.

ALTER TABLE `blog_post` CHANGE `site_id` `site_id` INT( 11 ) NOT NULL ;

New record doesn’t need the default value. So I unset it just in case.

ALTER TABLE `blog_post` ADD UNIQUE `site_id` ( `site_id` , `slug` , `date` ) ;
ALTER TABLE `blog_post` ADD INDEX `blog_post_site_id` ( `site_id` ) ;

For blogroll.Link model’s table:

ALTER TABLE `blogroll_link` ADD `site_id` INT( 11 ) NOT NULL DEFAULT '1' AFTER `user_id` ;
ALTER TABLE `blogroll_link` CHANGE `site_id` `site_id` INT( 11 ) NOT NULL ;
ALTER TABLE `blogroll_link` ADD INDEX `blogroll_link_site_id` ( `site_id` ) ;

In reality, I used phpMyAdmin instead of typing commands. Finally, I ran manage.py syncdb command to synchronize models with tables.

At the moment, it seems to me that everything is all right and I’m very comfortable.

Add post to:   Delicious Reddit Slashdot Digg Technorati Google
Make comment

Comments

I went across the article “Making Changes to a Database Schema” and found it more helpful for me.

Required. 30 chars of fewer.

Required.

captcha image Please, enter symbols, which you see on the image