Migration error when using jSON field on MariaDB - laravel

After trying to add a new jSon column to my Users table, I am getting an error related to field size. I blame MariaDB because they can't see the future, but is there a way to override this error without changing my field type to BLOB or TEXT?
Here is my up method in the migration:
public function up(){
Schema::table( 'users', function( Blueprint $table ){
$table->json( 'options' )->nullable();
} );
}
This is the error I get:
In Connection.php line 669:
SQLSTATE[42000]: Syntax error or access violation: 1118 Row size too large. The maximum row siz
e for the used table type, not counting BLOBs, is 8126. This includes storage overhead, check t
he manual. You have to change some columns to TEXT or BLOBs (SQL: alter table `users` add `opti
ons` json null)
In PDOStatement.php line 129:
SQLSTATE[42000]: Syntax error or access violation: 1118 Row size too large. The maximum row siz
e for the used table type, not counting BLOBs, is 8126. This includes storage overhead, check t
he manual. You have to change some columns to TEXT or BLOBs
In PDOStatement.php line 127:
SQLSTATE[42000]: Syntax error or access violation: 1118 Row size too large. The maximum row siz
e for the used table type, not counting BLOBs, is 8126. This includes storage overhead, check t
he manual. You have to change some columns to TEXT or BLOBs

Related

Eloquent Intermediate Tabel with None Standard ID Column

While creating my database according to the eloquent standard, I ran into the problem that my table_name and id column name combined would be longer as 64 characters.
very_long_table_name.very_long_column_name_id
So I used a shorter column name as the foreign key in my Intermediate Table.
Migration file:
$table->unsignedBigInteger('short_id');
$table->foreign('short_id')->references('id')->on('very_long_table_name');
That worked fine, yet now I would like to insert a connection
Seeder.php:
$x->very_long_table_name()->attach($other_table_name->id);
I get the error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'very_long_column_name_id' in 'field list' (SQL: insert into very_long_table_name (just_an_id, very_long_column_name_id) values (1, 1))
What I would want is that it would use the column short_id instead of very_long_column_name_id to insert this, is there any cool way to fix this? or do I need to insert and query the connection manually if I keep the long names?
Like #Tim points out in the comments this needs to be done in the Model VeryLongTableName.php where you define the relationship:
public function very_long_table_name() {
return $this->belongsToMany(Model::class, 'very_long_table_name', 'local_id', 'short_id');
}

duplicate key value violates unique constraint Laravel and Postgresql

I try to add a new value to db, but I got this error.
SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value
violates unique constraint "lkp_locations_pkey"↵DETAIL: Key
(id)=(1) already exists. (SQL: insert into "lkp_locations" ("tex...
If I Replay the XHR ,the ID is increased, until I have an ID available ,and then the value is stored. From what I read is something about Postgres, but I am not sure what to change. Link:
$lkp_abode->fill([
'text' => $request->lkp_abode_text,
])->save();

Lumen 5.1 - many to many sync is missing data

I'm trying to create a reusable method for creating a relationship for a many to many pivot table but it seems to be missing the listing_id when trying to sync the data.
$model = $this->model->findOrFail($model_id)->with($relation);
return $model->getRelation($relation)->sync($data);
Returns:
integrity constraint violation: 1048 Column 'listing_id' cannot be null (SQL: insert into `tenants_listings` (`created_at`, `listing_id`, `tenant_id`, `updated_at`) values (2019-03-01 11:10:36, , ef4c9d60-a7a3-3340-8dd0-a901d624cd97, 2019-03-01 11:10:36)
This works perfectly fine when done like this:
$model = $this->model->findOrFail($model_id)->tenants();
return $model->sync($data);

How alter column type with using toUInt32OrZero function in clickhouse?

I have String column in clickhouse table.
I try alter table with modify type to UInt32:
ALTER TABLE main.abonents
MODIFY COLUMN
device_type UInt32 DEFAULT 0
but have error:
Received exception from server:
Code: 6. DB::Exception: Received from 5.200.55.122:9000. DB::Exception: Cannot parse string 'mo' as UInt32: syntax error at begin of string. Note: there are toUInt32OrZero function, which returns zero instead of throwing exception..
It's clear, clickhouse use toUint32 function on string like 'mobile' and throw exception. And its advice to use function toUInt32OrZero to convert type.
How can i use toUInt32OrZero function with ALTER TABLE??
There's no such way (as far as I know).
You can achieve it with a second table. Let's create one:
CREATE TABLE main.abonents_new AS main.abonents;
Then we have to alter column in that new table.
This table has no data yet, so it won't raise exceptions:
ALTER TABLE main.abonents_new MODIFY COLUMN device_type UInt32 DEFAULT 0;
Then, make sure no new data is written to main.abonents. We'd like to keep everything in place when we'll transfer the data to the new table.
Insert the data using INSERT INTO SELECT query. Make sure to list all the fields with the same order; wrap device_type to the converter function (toUInt32OrZero) :
INSERT INTO main.abonents_new SELECT field1, field2, ..., toUInt32OrZero(device_type) AS device_type, ..., fieldN FROM main.abonents;
Then, make sure that everything's alright (that rows count is the same, device_type was converted as intended, etc), then rename the tables:
RENAME TABLE main.abonents TO main.abonents_old;
RENAME TABLE main.abonents_new TO main.abonents;
(or, you may DROP the older table instead; although I'd keep the old data to be able to restore if things'd go south)

Advantage Database Server 8.1 UNIQUE CONSTRAINT multiple columns

I am working on an Advantage Database Server 8.1 and I have created a new table. I want to add a unique constraint for the combination of 2 columns.
I tried
ALTER TABLE TableName
ADD CONSTRAINT ConstraintName
UNIQUE (ColumnName1, ColumnName2)
but I get the error
"ERROR IN SCRIPT: poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [Extended Systems][Advantage SQL Engine]Expected lexical element not found: You are missing the column names. -- Location of error in the SQL
statement is: 33 (line: 2 column: 5)"
Ok the solution I found is:
CREATE UNIQUE INDEX ConstraintName ON TableName (ColumnName1, ColumnName2);

Resources