You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been playing around Schema Builder and for some reason it will not longer create the 2nd table and it will not create composite key on the second table. I can run plain SQL (test SQL below) and get it done so unsure.
Running latest version of Laravel.
PHP 5.5
mySQL 5.5.34-cll-lve
Apache 2.2.25
if(DB::connection()->getDatabaseName())
{
echo "connected sucessfully to database ".DB::connection()->getDatabaseName();
}
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
USE matrixme_matrixme ;
-- Table matrixme_matrixme.users
CREATE TABLE IF NOT EXISTS matrixme_matrixme.users ( userid INT UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(100) NULL, firstname VARCHAR(100) NULL, lastname VARCHAR(100) NULL,
PRIMARY KEY (userid))
ENGINE = InnoDB;
-- Table matrixme_matrixme.user groups
CREATE TABLE IF NOT EXISTS matrixme_matrixme.user groups ( groupid INT UNSIGNED NOT NULL AUTO_INCREMENT, userid INT UNSIGNED NOT NULL, admininstrator INT UNSIGNED NOT NULL,
PRIMARY KEY (groupid, userid, admininstrator),
INDEX fk_user_id_idx (userid ASC),
CONSTRAINT fk_user_id
FOREIGN KEY (userid)
REFERENCES matrixme_matrixme.users (userid)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
ERROR IN LOG FILE (weird as it was working beforehand and just stopped working)
I'm pretty sure the increments and bigIncrements types automatically make themselves primary keys, so explicitly declaring that column as the primary key later will cause a conflict.
It does seem like a bug if you can only create autoincrement/serial columns if they are the primary key.
I've tried it with both int,x and int types, still the same problem. Weird thing it was work fine then went South as I started working with composite keys. Even if I remove the primary key and add one field in the 2nd table I still have the same issue. SQL script, not problem, Schema builder ... nope. I've been running migrate on a number of apps lately without problems so I figure it is a user error :)
I've been playing around Schema Builder and for some reason it will not longer create the 2nd table and it will not create composite key on the second table. I can run plain SQL (test SQL below) and get it done so unsure.
if(DB::connection()->getDatabaseName())
{
echo "connected sucessfully to database ".DB::connection()->getDatabaseName();
}
Schema::create('users', function($usertable)
{
});
Schema::create('usergroups', function($usrgrptable)
{
$usrgrptable->bigIncrements('groupid');
$usrgrptable->bigInteger('userid', 20);
$usrgrptable->bigInteger('administrator', 20);
$usrgrptable->primary(array('groupid','userid','adminstrator'));
});
TEST SQL THAT WORKS FINE
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
USE
matrixme_matrixme
;-- Table
matrixme_matrixme
.users
CREATE TABLE IF NOT EXISTS
matrixme_matrixme
.users
(userid
INT UNSIGNED NOT NULL AUTO_INCREMENT,username
VARCHAR(100) NULL,firstname
VARCHAR(100) NULL,lastname
VARCHAR(100) NULL,PRIMARY KEY (
userid
))ENGINE = InnoDB;
-- Table
matrixme_matrixme
.user groups
CREATE TABLE IF NOT EXISTS
matrixme_matrixme
.user groups
(groupid
INT UNSIGNED NOT NULL AUTO_INCREMENT,userid
INT UNSIGNED NOT NULL,admininstrator
INT UNSIGNED NOT NULL,PRIMARY KEY (
groupid
,userid
,admininstrator
),INDEX
fk_user_id_idx
(userid
ASC),CONSTRAINT
fk_user_id
FOREIGN KEY (
userid
)REFERENCES
matrixme_matrixme
.users
(userid
)ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
ERROR IN LOG FILE (weird as it was working beforehand and just stopped working)
[2014-05-26 20:13:53] production.ERROR: exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (SQL: alter table
users
add primary key users_userid_primary(userid
))' in /home/matrixme/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:555Stack trace:
#0 /home/matrixme/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(338): Illuminate\Database\Connection->run('alter table
us...', Array, Object(Closure)) #1 /home/matrixme/public_html/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php(63): Illuminate\Database\Connection->statement('alter table
us...')#2 /home/matrixme/public_html/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(169): Illuminate\Database\Schema\Blueprint->build(Object(Illuminate\Database\MySqlConnection), Object(Illuminate\Database\Schema\Grammars\MySqlGrammar))
#3 /home/matrixme/public_html/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(112): Illuminate\Database\Schema\Builder->build(Object(Illuminate\Database\Schema\Blueprint))
#4 /home/matrixme/public_html/bootstrap/compiled.php(3165): Illuminate\Database\Schema\Builder->create('users', Object(Closure))
#5 /home/matrixme/public_html/app/routes.php(42): Illuminate\Support\Facades\Facade::__callStatic('create', Array)
#6 /home/matrixme/public_html/app/routes.php(42): Illuminate\Support\Facades\Schema::create('users', Object(Closure))
#7 [internal function]: {closure}()
#8 /home/matrixme/public_html/bootstrap/compiled.php(4954): call_user_func_array(Object(Closure), Array)
#9 /home/matrixme/public_html/bootstrap/compiled.php(4669): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#10 /home/matrixme/public_html/bootstrap/compiled.php(4657): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#11 /home/matrixme/public_html/bootstrap/compiled.php(706): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#12 /home/matrixme/public_html/bootstrap/compiled.php(687): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#13 /home/matrixme/public_html/bootstrap/compiled.php(1144): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#14 /home/matrixme/public_html/bootstrap/compiled.php(7264): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
#15 /home/matrixme/public_html/bootstrap/compiled.php(7861): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#16 /home/matrixme/public_html/bootstrap/compiled.php(7808): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#17 /home/matrixme/public_html/bootstrap/compiled.php(10820): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#18 /home/matrixme/public_html/bootstrap/compiled.php(648): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#19 /home/matrixme/public_html/public/index.php(49): Illuminate\Foundation\Application->run()
#20 {main} [] []
The text was updated successfully, but these errors were encountered: