Laravel Drop Renamed index - laravel

I created an index with laravel index()
$table->index(['group_tasks_outline_agreement_uuid'], 'gt_oa_uuid');
I have been tried to drop this idex with dropIndex()
$table->dropIndex(['group_tasks_outline_agreement_uuid']);
or
$table->dropIndex(['gt_oa_uuid']);
it shows the error msg : Syntax error or access violation: 1091 Can't DROP INDEX hps_purchase_order_hps_purchase_order_uuid_index; check that it exists

It should be
$table->index(['group_tasks_outline_agreement_uuid'], 'group_tasks_outline_agreement_gt_oa_uuid_index');

Related

"Syntax error or access violation: 1064" When changing column type from string to integer [LARAVEL MIGRATION]

In the down() function of my migration i have the following line:
$table->integer('placeholder')->change();
Here I try to change the column type 'number' from string(750 characters) to integer. Whenever I try to run this rollback, I get hit with:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax
This also happens when I try to change the column to something else (such as a boolean). Setting the amount of characters from 750 to 191, so: $table->string('placeholder',191)->change(); does work.
The table I'm working in currently does not contain any data & i'm using the utf8mb4 character-set
Are you sure your column name is number? It is a keyword in mysql and such column names cannot be used unless you quote it like `number`. It is not a good practice to use such keywords as a column name.
Perhaps in the current table you have filled in the column 'placeholder' that does not correspond to the new rules of this column.
Create a migration with new temporary column $ table-> string
('temp_placeholder', 191)
Write a seeder to transfer data from the 'placeholder' column to 'temp_placeholder', taking into account the new specified rules for the column.
Create a migration to delete the 'placeholder' column and rename the 'temp_placeholder' column to 'placeholder'

Laravel Sqlite column index out of range

When running tests using phpunit I'm getting a not so nice exception
SQLSTATE[HY000]: General error: 25 column index out of range (SQL: select count(*) as aggregate from "attachments" where "id" = f3bad3ad-a888-41bc-b6fd-9a5998f6b527
The Attachment.Id is a UUID and the column is defined as primary key. When running the tests I am using SQLite with an in-memory db.
When switching over to MySQL I do not get an error anymore. I don't really know why the query would cause an error.
Any tips?
1) Make sure the property public $incrementing = false; is set on the model.
2) The migration should be $table->uuid('id')->primary();
3) Add the below function to the model:
public function getKeyType()
{
return 'string';
}
4) To diagnose, create a database.sqlite and allow the test to run on that DB. Diagnose the size of the ID column. Does it fit the UUID string? If it actually doesn't, you may have to update your Laravel app or edit your migrations so if it's running on Sqlite, it will create a string column with the appropriate length.

After Upgrade to Magento 2.2.2: Duplicate entry '0-0-0-0' for key 'PRIMARY', query was: INSERT INTO `salesrule_product_attribute` () VALUES ()

If I Upgrade Magento from 2.1.8 to 2.2.2 and run setup:upgrade I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-0-0-0' for key 'PRIMARY', query was: INSERT INTO `salesrule_product_attribute` () VALUES ()
If I truncate all salesrule tables it works, but I can't do this on a production environment. Is there any workaround for this issue?
The problem is in the file vendor/magento/module-sales-rule/Model/ResourceModel/Rule.php.
The method setActualProductAttributes inserts empty VALUES() if $data is empty.
This can be fixed by overriding the Model and replace
$connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);
with:
if(count($data > 0 )) {
$connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);
}

updateOrCreate return duplicate error while it should update

My understanding of Laravel updateOrCreate is that if a given value exists updates the table otherwise adds a new record but I have encounter as situation that instead of updating it give me the duplicate error. This is what I have:
$e = \App\Element::updateOrCreate(
['link' => $link],
['title'=>$title,'description' => $description]
This works fine but for one record I get:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'blahblahblah' for key 'link'
I wonder why updateOrCreate doesn't work here as it should. Shouldn't it leave the link column as it is and update the rest?

Pimcore 3.1.1 ALTER TABLE BUG

I installed Pimcore 3.1.1 and I have lot of issue with message like:
(
[message] => SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'p_index_person__id'; check that column/key exists, query was: ALTER TABLE `object_store_3` DROP INDEX `p_index_person__id`;
[method] => query
[arguments] => Array
(
[0] => ALTER TABLE `object_store_3` DROP INDEX `p_index_person__id`;
)
)
(
[message] => SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'p_index_person__type'; check that column/key exists, query was: ALTER TABLE `object_store_3` DROP INDEX `p_index_person__type`;
[method] => query
[arguments] => Array
(
[0] => ALTER TABLE `object_store_3` DROP INDEX `p_index_person__type`;
)
)
(
[message] => SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'p_index_Options'; check that column/key exists, query was: ALTER TABLE `object_store_12` DROP INDEX `p_index_Options`;
[method] => query
[arguments] => Array
(
[0] => ALTER TABLE `object_store_12` DROP INDEX `p_index_Options`;
)
)
Same errors are reported in Pimcore forum at the bottom of the post.
Is there an issue about this ? Currently, I can't work with Pimcore. Every change in object structure corrupts the data.
Any advice ?
UPDATE #001 :
I have tried Johan's solutions :
First one
Backup your entire system
Export class defintions from within admin
Import class definitions from within admin, save class
Second
Export the class definitios from within admin
Remove files in website/var/classes
Import your class definitions again
I always have the same errors in log with alter table.
When I try to add an ObjectBricks to my object, I see this :
Thanks for your help.
Have a nice day.
you could try to
Backup your entire system
Export class defintions from within admin
Import class definitions from within admin, save class
If that does not do the trick then you could try to (be sure you did a backup Before and know your recover steps)
Export the class definitios from within admin
Remove files in website/var/classes
Import your class definitions again
/Johan

Resources