0

I've given up trying to make the SQL script for my custom module work, tried all sorts of things online and realized I've spent an hour on it when I can just manually create the table.

Just checking there isn't any issues with this? Like is there any foreign key checks etc.

EDIT

My install script:

$installer = $this;

$installer->startSetup();

$installer->run("

CREATE TABLE IF NOT EXISTS `datasheetadmin_datasheetadmin` (
  `DatasheetAdmin_id` int(11) unsigned NOT NULL auto_increment,
  `attribute_set_id` int(11)  NOT NULL,
  `header_row` text NOT NULL default '',
  `product_row` text NOT NULL default '',
  `custom_product_id` int(11) NOT NULL default 0,
  PRIMARY KEY (`DatasheetAdmin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    ");

$installer->endSetup();
1
  • It depends on what you want to achieve. Maybe if you post your install script we can help you fixing it so you don't have to add the table manually? Commented Jan 19, 2016 at 15:07

1 Answer 1

1

The main problem is that your table will not be portable.
Each time you want your functionality that requires this table deployed on an instance you will have to create the table by yourself.
it's not a huge issue if you only have one table, but if do this once, you will do it again. Then you will lose track of what's what. I still think you should create your table via script.
Here is how.

Create a module (let's call it StackExchange_Demo). Files needed:

app/etc/modules/StackExchange_Demo.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Demo>
            <active>true</active>
            <codePool>local</codePool>
        </StackExchange_Demo>
    </modules>
</config>

app/code/local/StackExchange/Demo/etc/config.xml - the config file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Demo>
            <version>1.0.0</version>
        </StackExchange_Demo>
    </modules>
    <global>
        <resources>
            <stackexchange_demo_setup>
                <setup>
                    <module>StackExchange_Demo</module>
                </setup>
            </stackexchange_demo_setup>
        </resources>
    </global>
</config>

app/code/local/StackExchange/Demo/sql/stackexchange_demo_setup/install-1.0.0.php - the sql install script. When creating table you should use the DDL way of doing it, but if you can't do this you can take the simple approach:

<?php
$installer = $this;
$installer->startSetup();
$installer->run("CREATE TABLE SQL STATEMENT GOES HERE");
$installer->endSetup();

Clear the cache and you are done.

3
  • could you tell me if theres anything wrong with my install script, did the rest of what you said :) Commented Jan 19, 2016 at 15:19
  • I see nothing wrong at a first glance. did you clear the cache?
    – Marius
    Commented Jan 19, 2016 at 15:20
  • it was an issue with my config and some other stuff, mainly using app/code/local/StackExchange/Demo/sql/demo_setup/install-1.0.0.php instead of app/code/local/StackExchange/Demo/sql/stackexchange_demo_setup/install-1.0.0.php Commented Jan 19, 2016 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.