diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index eff785a2a..44edc9cad 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -148,7 +148,14 @@ class Table extends AbstractAsset */ public function setPrimaryKey(array $columns, $indexName = false) { - return $this->_createIndex($columns, $indexName ?: "primary", true, true); + $primaryKey = $this->_createIndex($columns, $indexName ?: "primary", true, true); + + foreach ($columns AS $columnName) { + $column = $this->getColumn($columnName); + $column->setNotnull(true); + } + + return $primaryKey; } /** diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index b7830097e..1b39d9d32 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -341,4 +341,16 @@ class TableTest extends \PHPUnit_Framework_TestCase $this->assertTrue($table->hasIndex('my_idx')); $this->assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns()); } + + public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() + { + $table = new Table("foo"); + $column = $table->createColumn("id", 'integer', array('notnull' => false)); + + $this->assertFalse($column->getNotnull()); + + $table->setPrimaryKey(array('id')); + + $this->assertTrue($column->getNotnull()); + } } \ No newline at end of file