Category : sql

I’m addign a foreign key to my appointments table, my DB is called arl through laravel migrations but when I run migration: public function up() { Schema::table(‘appointments’, function (Blueprint $table) { $table->foreign(‘order_detail_id’)->references(‘id’)->on(‘order_details’); }); } I got this error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails ..

Read more

I’m getting some columns from various tables within my project and would look to obtain some additional information other than the column name, I’d like to get the column type as well. I’m usign the Schema::getColumnListing() method and am passing a table into it, I’m able to get the fields, but not the types? My ..

Read more

So I’m working on a project of "comment Insertion". Everything went perfect until i’ve a added a contact_id element… And I got this error : SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value. Here is my code : $contact_id = $contact_id !== null ? $contact_id : null; $user_id = auth()->check() ? auth()->user()->id : null; $log ..

Read more

I need to convert this querry that i got from Access to an laravel eloquent for my remake database project, thanks. SELECT T_Sites.Code_Region, T_Sites.Nom_Site, T_CLM.N_CLM, T_Port.N_Port, T_Vlan.IP_Vlan, T_Ref_Vlan.Id_Referentiel, T_Ref_Vlan.Nom_Vlan, T_Vlan.Dt_Creat, T_Vlan.Id_Vlan, T_Vlan.IP_HSRP, T_Vlan.IP_SousReseaux, T_CLM.Id_CLM, T_Vlan.Masque FROM (T_CLM INNER JOIN ((T_Port INNER JOIN T_Vlan ON T_Port.Id_Port = T_Vlan.Id_Port) LEFT JOIN T_Ref_Vlan ON T_Vlan.Id_Referentiel = T_Ref_Vlan.Id_Referentiel) ON ..

Read more

I’m having trouble converting my sql to Laravel Query. Hope to find help. Thank you. If possible, can anyone also tell me how find the difference between value after get the output from query select a.id, a.serial_number, (select sum(b.actual_generation) as ttl from smt_meter_reading b where b.smt_smart_meter_id=a.id and b.read_time between ‘2020-09-01 00:00:0’ and ‘2020-09-30 23:30:0’) as ..

Read more

I’m new to the programming world, I’m studying laravel on my own, and I got this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘clientes.clientes_id’ in ‘where clause’ (SQL: select * from clientes where clientes.clientes_id = 1 and clientes.clientes_id is not null) (View: /shared/httpd/laravel_8_crud/resources/views/pedidos/index.blade.php) Could someone help me with the case? My goal is to ..

Read more

I have a DB::select() query where I want to add dynamic SQL by variable. This is what I’m trying to do but it returns SQL syntax error. $restaurantSql = ""; $restaurantIds = [6,43,51]; if ($someOtherVariable) { $restaurantSql = "AND orders.restaurant_ids IN (".implode(",", $restaurantIds).")"; } $result = DB::select( "SELECT * FROM orders JOIN restaurants ON orders.restauant_id ..

Read more

I got this error while I’m trying to finish the payment processing from payPal: SQLSTATE[HY000]: General error: 1364 Field ‘trans_id’ doesn’t have a default value (SQL: insert into transactions (amount, sender, type, currency, description, fee, client_id, status, receiver, updated_at, created_at) values (1.00, [email protected]mple.com, paypal, USD, Your transaction description, 0, 1, approved, [email protected], 2021-02-19 23:11:39, 2021-02-19 ..

Read more

DataTables warning: table id=datauser – Exception Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘users.nama’ in ‘where clause’ (SQL: select count(*) as aggregate from (select ‘1’ as row_count from users left join tb_operator on tb_operator.user_id = users.id left join tb_mahasiswa on tb_mahasiswa.user_id = users.id where (LOWER(users.username) LIKE %k% or LOWER(users.nama) LIKE %k% or LOWER(users.role) LIKE ..

Read more

Hola mi problema es que necesito convertir una consulta plana a laravel eloquent solo me esta faltando es seleccionar ambas consultas y agregarle el ALIAS "a" como se ve abajo SELECT * FROM ( SELECT `punto_venta`.`tienda_id`, `punto_venta`.`codigo_personal`, `punto_venta`.`created_at` AS `fecha_emision`, `tipo_documento`.`descripcion` AS `tipo_documento`, `punto_venta`.`nro_documento`, `punto_venta`.`total` AS `total_venta`, `tiendas`.`descripcion` AS `tienda`, CONCAT( personal.nombre, ‘ ‘, personal.apellidos ..

Read more

Let’s assume that I have 2 tables: Users: Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’); $table->string(‘name’); $table->string(’email’)->unique(); $table->integer(‘age’) $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); Phones: Schema::create(‘phones’, function (Blueprint $table) { $table->increments(‘id’); $table->integer(‘user_id’)->unsigned(); $table->string(‘phone’); $table->timestamps(); $table->foreign(‘user_id’)->references(‘id’)->on(‘users’) ->onDelete(‘cascade’); }); User Model: public function phone() { return $this->hasOne(‘AppPhone’); } Phone Model: public function user() { return $this->belongsTo(‘AppUser’); } When I perform ..

Read more