Tuesday 29 June 2010

PowerShell in Windows 7

In my current project we are using PowerShell in our build & deployment scripts. It's a useful tool offering a greatly extended set of commands comparing to regular cmd. On Windows XP I needed to install this manually but in Windows 7 PowerShell comes with the system.

Recently I changed my machine and system (XP -> W7) and discovered that the scripts don't work anymore. The reason for that was the insufficient execution policy set in PowerShell by default. I changed it to the one previously used on my old machine and... no effect!

I started to think that the problem may not be caused by execution policy (although the error message was quite obvious) but then I found out there are actually 2 PowerShell versions installed: 64 a 32 bit. You can find them under "Windows PowerShell" folder in Accessories:

2 versions of PowerShell in Windows 7

Changing execution policy for both versions solved my problem.

Friday 25 June 2010

Mysql foreign keys don't work

Recently I've been working on a small PHP+MySql project. I designed a database schema that contains multiple tables, some of them with FOREIGN KEY constraint defined. After my model was ready I exported it to SQL format and created the actual database from the script. I was very surprised discovering that the defined foreign keys constraints don't work i.e. I could add any data to the constrained columns regardless the content of referenced table.

Solution:
It came out that the problem was caused by the default ENGINE used by my MySql database i.e. MyISAM. Foreign key constraint is not implemented in its current version (read more here). To enable the FOREIGN KEY constraint I decided to use InnoDb ENGINE. I forced that by adding engine selection for each table:


CREATE TABLE IF NOT EXISTS `my_table` (
`id` INT NOT NULL ,
`other_table_id` INT NOT NULL ,
PRIMARY KEY (`id`) ,
FOREIGN KEY (`other_table_id` ) REFERENCES `other_table` (`id`)
) ENGINE = InnoDB;