I'm working on creating a Joomla component for Joomla 2.5, but I'm having trouble with the installation script. In the install.mysql.utf8.sql
file I have the following content:
DROP TABLE IF EXISTS `#__products`;
CREATE TABLE `#__products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`description` varchar(128) NOT NULL,
`price` int(11) NOT NULL,
`published` tinyint(1) NOT NULL DEFAULT 1,
`url` varchar(255),
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
# Insert default values
INSERT INTO `#__products` (`name`, `description`, `price`, `url`) VALUES
('product1', 'description1', 1000, 'image.png'),
('product2', 'description2', 2000, 'image.png'),
('product3', 'description3', 4000, 'image.png');
When I install the component, Joomla says it was successfull. However, when I check the database the default values have not been added to the product table even though the table got created. If I run the INSERT
directly in mysql it works just fine (have to change the name of the table of course).
If i were to include a typo in the SQL-script I get an error, so I don't see how it's a problem with my MySQL syntax. Does anyone have any clues of what might be going on here, and how to solve it?
Thanks.
I finally got it to work. The only thing I did was to remove the DROP TABLE IF EXISTS
at the top of the SQL-file, and change the CREATE
-statement to start with a CREATE TABLE IF NOT EXISTS
. That was it.
I'm not sure why this works, but it could be that the insert does not work because the table hasn't been properly deleted/created when the insert is being executed. Hope this will help someone else!