Ошибка сопоставления внешних ключей Sql-скрипта magento


У меня есть 2 таблицы spen_recipe и тип spen_recipe_type

Spen_recipe содержит столбцы

1) идентификатор рецепта PK

2) тип рецепта FK

Spen_recipe_tpye содержит столбцы

1) идентификатор типа рецепта PK

Нет, мне нужно сопоставить тип рецепта (FK) из 1-й таблицы с идентификатором типа рецепта (PK) во 2-й таблице.

Для этого у меня есть свой скрипт в виде:

->addForeignKey(
$this->getFkName('vendor_recipe/spen_recipe','recipe_type', 'vendor_recipe/spen_recipe_type','recipe_type_id'),
    'recipe_type',
$this->getTable('vendor_recipe/spen_recipe_type'),
    'recipe_type_id',
Varien_Db_Ddl_Table::ACTION_CASCADE,
Varien_Db_Ddl_Table::ACTION_CASCADE
) 

Обновлено полностью код:

$installer = $this;

$installer->startSetup();

$table = $installer->getConnection()
->newTable($installer->getTable('vendor_recipe/spen_recipe'))
->addColumn('recipe_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'identity'  => true,
    'unsigned'  => true,
    'nullable'  => false,
    'primary'   => true,
    ), 'Recipe ID')
->addColumn('user_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    ), 'USer ID')
->addColumn('recipe_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
    'nullable'  => false,
    ), 'Recipe Name')
->addColumn('recipe_title', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
    'nullable'  => false,
    ), 'User ID')
->addColumn('spen_recipe_type', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    ), 'Recipe Type')
->addColumn('cooking_time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    ), 'Cooking Time')
->addColumn('preparation_time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    ), 'Preparation time')
->addColumn('serving_to', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    ), 'Serving to')
->addColumn('recipe_desc', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
    'nullable'  => false,
    ), 'Recipe Description')
->addColumn('recipe_photo', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
    'nullable'  => false,
    ), 'Recipe Photo')
->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
    'nullable'  => false,
    ), 'Created At')
->addColumn('modified_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
    'nullable'  => false,
    ), 'Modified At')
->addColumn('published_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
    'nullable'  => false,
    ), 'Published At')
 ->addForeignKey(
    $this->getFkName('vendor_recipe/spen_recipe','recipe_type', 'vendor_recipe/spen_recipe_type','recipe_type_id'),
        'recipe_type',
    $this->getTable('vendor_recipe/spen_recipe_type'),
        'recipe_type_id',
    Varien_Db_Ddl_Table::ACTION_CASCADE,
    Varien_Db_Ddl_Table::ACTION_CASCADE
) 
->setComment('Spen Recipe Table');

$установщик->getConnection()->Создать таблицу ($таблица);

Я получаю неопределенный столбец "recipe_type".

Author: Sushivam, 2016-11-03

1 answers

Я надеюсь, что вы пытаетесь addForeignKey перейти к таблице spen_recipe, а не к таблице spen_recipe_type. Обычно вы должны получать это сообщение об ошибке в случае, если вы попытаетесь выполнить addForeignKey во второй таблице (spen_recipe_type), которая не содержит столбец recipe_type.

 0
Author: Tudor, 2016-11-03 08:36:26