Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Migration error
  • Hello there, i've got a problem: when i try to do oil refine migrate with my following script, i got an error:
    Error - Foreign keys on create_table() must specify a reference table and column name in COREPATH/classes/dbutil.php on line 381

    My migration script:
    <?php
    
    namespace Fuel\Migrations;
    
    class Initial_db_model
    {
    
        function up()
        {
            // Create table `organizations`
            \DBUtil::create_table('organizations', array(
                'id' => array('type' => 'int', 'constraint' => 5, 'auto_increment' => true),
                'apikey' => array('type' => 'varchar', 'constraint' => 32),
                'system_uri' => array('type' => 'text'),
                'name' => array('type' => 'varchar', 'constraint' => 45),
                'active' => array('type' => 'boolean'),
                'created_at' => array('type' => 'timestamp', 'detault' => \DB::expr('CURRENT_TIMESTAMP')),
                'updated_at' => array('type' => 'timestamp', 'null' => true)
            ), array('id'));
            \DBUtil::create_index('organizations', 'apikey', 'apikey_UNIQUE', 'UNIQUE');
            \DBUtil::create_index('organizations', 'apikey', 'apikey_INDEX');
            
            // Create table `shops`
            \DBUtil::create_table('shops', array(
                'id' => array('type' => 'varchar', 'constraint' => 32),
                'active' => array('type' => 'boolean'),
                'name' => array('type' => 'varchar', 'constraint' => 45),
                'created_at' => array('type' => 'timestamp', 'detault' => \DB::expr('CURRENT_TIMESTAMP')),
                'updated_at' => array('type' => 'timestamp', 'null' => true)
            ),  array('id'), true, false, null, array(
                    'key' => 'organizations_id',
                    'reference' => array(
                        'table' => 'organizations',
                        'column' => 'id')
                    )
            );
        }
    
        function down()
        {
           \DBUtil::drop_table('shops');
           \DBUtil::drop_table('organizations');
        }
    }
    
  • $foreign_keys is a multi-dimensional array (as you can define multiple entries). See the documentation.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion