wemersonrv

Laravel Migrations - Erro ao criar Foreign Keys

Oct 31st, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. // Classe Pessoa
  2. class Create_Pessoas {
  3.     public function up(){
  4.         Schema::create('pessoa', function($table){
  5.             $table->increments("ID");
  6.             $table->string('nome', 128);
  7.             $table->timestamps();
  8.         });
  9.         DB::table('pessoa')->insert(array(
  10.             'nome'      => 'Job Control Administrador',
  11.             'created_at'    => Date('H-m-d H:i:s'),
  12.             'updated_at'    => Date('H-m-d H:i:s'),
  13.         ));
  14.     }
  15.  
  16.     public function down(){
  17.         Schema::drop('pessoa');
  18.     }
  19. }
  20.  
  21. // Especialização da classe para Usuario
  22. class Create_Usuarios {
  23.     public function up(){
  24.         Schema::create('usuario', function($table){
  25.             $table->integer("pessoa_ID")->unsigned();
  26.             $table->string('login', 20);
  27.             $table->string('senha', 64);
  28.         });
  29.         Schema::table('usuario', function($table){
  30.             $table->foreign('pessoa_ID')->references('ID')->on('pessoa')->on_delete('cascade');
  31.         });
  32.  
  33.         DB::table('usuario')->insert(array(
  34.             'login'  => 'admin',
  35.             'senha'  => Hash::make('senha'),
  36.             'pessoa_ID' => 1, // Primeira pessoa adicionada, logicamente com o ID nº 1
  37.         ));
  38.     }
  39.  
  40.     public function down(){
  41.         Schema::drop('usuario');
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment