addForeignKey example


        $sqlTable = new Table($this->db, $this);

        return $sqlTable->fromTable($this->db->DBPrefix . $table)
            ->dropPrimaryKey()
            ->run();
    }

    public function addForeignKey($fieldName = '', string $tableName = '', $tableField = '', string $onUpdate = '', string $onDelete = '', string $fkName = ''): BaseForge
    {
        if ($fkName === '') {
            return parent::addForeignKey($fieldName$tableName$tableField$onUpdate$onDelete$fkName);
        }

        throw new DatabaseException('SQLite does not support foreign key names. CodeIgniter will refer to them in the format: prefix_table_column_referencecolumn_foreign');
    }

    /** * Generates SQL to add primary key * * @param bool $asQuery When true recreates table with key, else partial SQL used with CREATE TABLE */
    protected function _processPrimaryKeys(string $table, bool $asQuery = false): string
    {
$this->forge->addUniqueKey($key['fields']$keyName);
                        break;

                    case 'index':
                        $this->forge->addKey($key['fields'], false, false, $keyName);
                        break;
                }
            }
        }

        foreach ($this->foreignKeys as $foreignKey) {
            $this->forge->addForeignKey(
                $foreignKey->column_name,
                trim($foreignKey->foreign_table_name, $this->db->DBPrefix),
                $foreignKey->foreign_column_name
            );
        }

        return $this->forge->createTable($this->tableName);
    }

    /** * Copies data from our old table to the new one, * taking care map data correctly based on any columns * that have been renamed. */
Home | Imprint | This part of the site doesn't use cookies.