• ENTRAR
  • No hay productos en el carrito.

problemas al crear las migraciones

Viendo 9 publicaciones - del 1 al 9 (de un total de 9)
  • Autor
    Publicaciones
  • #4082

    Noe Moreno Poyatos
    Participante

    D:\DesarrollosWeb\curso7>php artisan migrate –pretend
    Migration table created successfully.
    [Symfony\Component\Debug\Exception\FatalThrowableError]
    Call to undefined method Illuminate\Database\Schema\Blueprint::SoftDelete()

     

    He probado el quitar la línea SoftDelete() pero me da error igual:

    D:\DesarrollosWeb\curso7>php artisan migrate –pretend
    Migration table created successfully.
    CreateTableUsers: create table users (id int unsigned not null auto_increment primary key, username varchar(60) not null, email varchar(100) not null, password varchar(60) not null, ip_address varchar(45) not null, api_token varchar(100) not null, created_at timestamp null, updated_at timestamp null) default character set utf8 collate utf8_unicode_ci
    CreateTableOwners: create table owners (id int unsigned not null auto_increment primary key, user_id int unsigned not null, phone_number varchar(10) not null, company_name varchar(100) not null, first_name varchar(100) not null, last_name varchar(100) not null, bio text not null, created_at timestamp null, updated_at timestamp null) default character set utf8 collate utf8_unicode_ci
    CreateTableOwners: alter table owners add constraint owners_user_id_foreign foreign key (user_id) references users () on delete cascade
    CreateTableLocals: create table locals (id int unsigned not null auto_increment primary key, owner_id int unsigned not null, name varchar(40) not null, description varchar(200) not null, logo varchar(100) not null, latitude double(8, 2) not null, longitude double(8, 2) not null, phone_number varchar(10) not null, city varchar(40) not null, created_at timestamp null, updated_at timestamp null) default character set utf8 collate utf8_unicode_ci
    CreateTableLocals: alter table locals add constraint locals_owner_id_foreign foreign key (owner_id) references owners () on delete cascade

    pero no logro ver donde está el error…

    #4086

    Cursosdesarrolloweb
    Jefe de claves

    Hola Noe,

    ¿Has ejecutado el código sql obtenido directamente en tu dbms?.

    #4088

    Noe Moreno Poyatos
    Participante

    El error me viene en :

    alter table owners add constraint owners_user_id_foreign foreign key (user_id) references users () on delete cascade<b></b><i></i><u></u>

    pero no veo el porqué…

    #4090

    Cursosdesarrolloweb
    Jefe de claves

    Hola Noe,

    Trata de ejecutar el siguiente comando en la primera migración, en este caso la de usuarios.

    
    $table->engine = 'InnoDB';
    

    O mejor aún, revisa si el motor de base de datos que estás utilizando es MYISAM o INNODB, debería ser INNODB ya que MYISAM no soporta relaciones, y ese error es típico al ejecutar estas consultas.

    Espero que eso pueda solucionar el problema.

    Saludos.

    #4093

    Noe Moreno Poyatos
    Participante

    Me sigue dando error, el motor es InnoDB.

    php artisan migrate –pretend

    Migration table created successfully.

    [Symfony\Component\Debug\Exception\FatalThrowableError]

    Call to undefined method Illuminate\Database\Schema\Blueprint::SoftDelete()

    #4095

    Cursosdesarrolloweb
    Jefe de claves

    ¿SoftDelete?

    
    Schema::create('owners', function (Blueprint $table)
    {
        $table->increments('id');
        $table->integer("user_id")->unsigned();
        $table->string("phone_number", 10);
        $table->string("company_name", 100);
        $table->string("first_name", 100);
        $table->string("last_name", 100);
        $table->text("bio");
        $table->timestamps();
    
        //Illuminate\Database\Schema\Blueprint::softDeletes()
        $table->softDeletes();
    
        $table->foreign("user_id")
            ->references("id")->on("users")
            ->onDelete("cascade");
    });
    
    #4098

    Noe Moreno Poyatos
    Participante

    Lapsus:

     

    una vez corregido:

    php artisan migrate –pretend

    Migration table created successfully.

    CreateTableUsers: create table users (id int unsigned not null auto_increment primary key, username varchar(60) not null, email varchar(100) not null, password varchar(60) not null, ip_address varc

    har(45) not null, api_token varchar(100) not null, created_at timestamp null, updated_at timestamp null) default character set utf8 collate utf8_unicode_ci engine = InnoDB

    CreateTableOwners: create table owners (id int unsigned not null auto_increment primary key, user_id int unsigned not null, phone_number varchar(10) not null, company_name varchar(100) not null, `fir

    st_namevarchar(100) not null,last_namevarchar(100) not null,biotext not null,created_attimestamp null,updated_attimestamp null,deleted_at` timestamp null) default character set utf8 collate

    utf8_unicode_ci

    CreateTableOwners: alter table owners add constraint owners_user_id_foreign foreign key (user_id) references users (id) on delete cascade

    CreateTableLocals: create table locals (id int unsigned not null auto_increment primary key, owner_id int unsigned not null, name varchar(40) not null, description varchar(200) not null, logo varch

    ar(100) not null, latitude double(8, 2) not null, longitude double(8, 2) not null, phone_number varchar(10) not null, city varchar(40) not null, created_at timestamp null, updated_at timestamp null

    , deleted_at timestamp null) default character set utf8 collate utf8_unicode_ci

    CreateTableLocals: alter table locals add constraint locals_owner_id_foreign foreign key (owner_id) references owners () on delete cascade

     

    y si hago sin la opcion –pretend

     

    php artisan migrate

    Migration table created successfully.

     

     

    [Illuminate\Database\QueryException]

    SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘) on delete c

    ascade’ at line 1 (SQL: alter table locals add constraint locals_owner_id_foreign foreign key (owner_id) references owners () on delete cascade)

     

     

     

    [PDOException]

    SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘) on delete c

    ascade’ at line 1

     

    #4100

    Noe Moreno Poyatos
    Participante

    Solucionado:
    $table->foreign(“owner_id”)
    ->reference(“id”)->on(“owners”)
    ->onDelete(“cascade”);

     

    Me faltaba una s, es references, muchas gracias

    #4102

    Cursosdesarrolloweb
    Jefe de claves

    Genial Noe :).

    Saludos!.

Viendo 9 publicaciones - del 1 al 9 (de un total de 9)

Debes estar registrado para responder a este debate.

Síguenos en las redes sociales para estar al tanto de los últimas novedades :)

Facebook
Facebook
Google+
Google+
https://www.cursosdesarrolloweb.es/forums/topic/problemas-al-crear-las-migraciones">
Pinterest
Pinterest
top
Cursosdesarrolloweb ©. Todos los derechos reservados.
🔓Inscríbete a cualquier curso por 9€ y accede a todos los cursos gratuitos para siempre🔓
🌍Los cursos gratuitos son exclusivos de esta plataforma, ÚLTIMOS CURSOS EN 4K🌍
+ +

Login

Create an Account Back to login/register