From 63aa35092b30c885b40e7369e232528620d7c175 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 11 Dec 2008 22:51:11 +0000 Subject: [PATCH] Merged r67482 to branches/2.3 - let db/build add auto_increment git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@68474 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Database.php | 4 +++- core/model/MySQLDatabase.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/model/Database.php b/core/model/Database.php index a19e9b78c..0eabfede2 100755 --- a/core/model/Database.php +++ b/core/model/Database.php @@ -224,7 +224,9 @@ abstract class Database extends Object { } else { $this->checkAndRepairTable($table); } - + + $this->requireField($table, "ID", "int(11) not null auto_increment"); + // Create custom fields if($fieldSchema) { foreach($fieldSchema as $fieldName => $fieldSpec) { diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index b179fd77d..c1e091f5e 100644 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -172,11 +172,11 @@ class MySQLDatabase extends Database { public function createTable($tableName, $fields = null, $indexes = null) { $fieldSchemas = $indexSchemas = ""; + if(!isset($fields['ID'])) $fields['ID'] = "int(11) not null auto_increment"; if($fields) foreach($fields as $k => $v) $fieldSchemas .= "`$k` $v,\n"; if($indexes) foreach($indexes as $k => $v) $fieldSchemas .= $this->getIndexSqlDefinition($k, $v) . ",\n"; $this->query("CREATE TABLE `$tableName` ( - ID int(11) not null auto_increment, $fieldSchemas $indexSchemas primary key (ID)