Declare Foreignkey in the database

I am a newbie to database and Yii framework. So I want to know that is it necessary to declare foreignkey constraint in the database or just by using codes to use as foreignkey is good?




CREATE TABLE IF NOT EXISTS `tbl_member` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `group_id` int(11) NOT NULL,

  `firstname` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',

  `lastname` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',

  `gender` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',

  `membersince` datetime NOT NULL,

  PRIMARY KEY (`id`),

  ----------------------------------

  KEY `FK_member_group` (`group_id`)

  ----------------------------------

) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=34 ;



I would declare the foreign key constraints in the database since it separates the relationship between data (business rules) from the logic in your app. It ensures integrity of your data. It is fine if all your transactions go through your app and the relation is declared there, but what if you do a batch upload through different door than your app? Will you remember to take that business rule into account?