本文整理汇总了PHP中yii\db\Migration::addPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::addPrimaryKey方法的具体用法?PHP Migration::addPrimaryKey怎么用?PHP Migration::addPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Migration
的用法示例。
在下文中一共展示了Migration::addPrimaryKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runCreateTable
/**
* Create table in database
*/
public function runCreateTable()
{
$this->dropTable();
if ($this->hideMigrationOutput) {
ob_start();
}
/** @var Connection $_conn */
$_conn = Yii::$app->{$this->db};
if (!$_conn->schema->getTableSchema($this->tableName)) {
$this->migrationClass->createTable($this->tableNameRaw, $this->columns);
if (is_array($this->primaryKeys) && sizeof($this->primaryKeys)) {
try {
$this->migrationClass->addPrimaryKey("{$this->tableNameRaw}_pk", $this->tableNameRaw, $this->primaryKeys);
} catch (\yii\db\Exception $exp) {
}
}
}
if ($this->hideMigrationOutput) {
ob_clean();
ob_flush();
}
}
示例2: addPrimaryKey
/**
* @inheritdoc
* Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
*/
public function addPrimaryKey($name, $table, $columns)
{
$table = $this->autoWrappedTableName($table);
return parent::addPrimaryKey($name, $table, $columns);
}
示例3: addPrimaryKey
/**
* @inheritdoc
* @param string|null $name
*/
public function addPrimaryKey($name, $table, $columns)
{
if (is_null($name)) {
$name = implode('-', (array) $columns);
}
parent::addPrimaryKey($name, $table, $columns);
}
示例4: addPrimaryKey
/**
* Builds and executes a SQL statement for creating a primary key.
* The method will properly quote the table and column names.
* @param string $table the table that the primary key constraint will be added to.
* @param string|array $columns comma separated string or array of columns that the primary key will consist of.
* @param string $name default null, the name of the primary key constraint.
*/
public function addPrimaryKey($table, $columns, $name = null)
{
$name = $name ?: $this->getNamePrimaryKey($table);
parent::addPrimaryKey($name, $table, $columns);
}
示例5: addPrimaryKey
public function addPrimaryKey($name, $table, $columns)
{
if (is_null($name)) {
$name = self::formIndexName($table, $columns, 'pk');
}
return parent::addPrimaryKey($name, $table, $columns);
}