I'm using Laravel's queue to retrieve data from API, when I'm being notified about changes through Webhooks. Webhook returns only id of the changed object, so I need to make a request to API to get the rest.
I dispatch the job to get the object by id, it runs in background (redis driver, supervisor). In queue I use:
Model::firstOrNew(['remote_id' => $id]);
but on ->save() I receive:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'tag-12' for key 'categories_type_remote_id_unique' (SQL: insert into categories...
If I debug this code using sync driver I can't reproduce this error, it only appears in background jobs. Like the job can't get the most recent data from DB and uses the new part of firstOrNew instead of first
the problem is for mysql .
you are entering duplicate entry 'tag-12'
find which keys you defined as unique . then change your firstOrNew method
Related
Am working on Laravel Nova 4.
I have a relational resource CustomerTicket where Customer.id and Ticket.id can appear together multiple times.
I want to query that table and get results of unique combinations of the foreign keys.
After receiving the results I want to send notifications to the customers about the Event of that Ticket.
Something like the code below (which is wrong)
CustomerCard::where('ticket_id', $ticket->id)->groupBy(['ticket_id', 'customer_id'])->get();
I am trying to set up the relations between my migrations in Laralvel 6, but I still have this error message and I do not understand why ....
When I want to publish an article, it takes the query but returns empty tables.
From the very limited information given, just by looking at the query it seems to be an issue with the user_id. In the insert stament there is no user_id inserted, which might be the problem? In your Article model, is user_id fillable?
If user_id isn't required, has it been made nullable in the migration for articles?
Please provide some examples of the migration, model and the method in the controller used for the create of the Article.
I am using the command :
# bin/connect-standalone.sh config/connect-standalone.properties config/debezium-config.properties
My debezium-config.properties is :
name=publications-connector
database.hostname=localhost
database.port=5432
database.user=andy
database.password=postgres
database.dbname=postgres
database.server.name=dbserver1
table.whitelist=public.publications
In Postgres, I have a table called publications
When I insert a new record into the publications table, I can see that my consumer shows the new message in json format.
However when I update an existing record into the publications, no new message is published to the topic and hence nothing to consume.
How can I fix this ?
Also, I would like to add another table 'comments' to my database. What changes do I need to make to the debezium-config.properties file or anywhere else to have those messages be published to its own topic ?
I see the following logs from the console :
WARN: no values found for table 'public.publications' from update message at 'source_info[server=dbserver1'db='postgres', .... schema=public, table=publications]'; skipping record (io.debezium.connector.postgres.RecordsStreamProducer:333)
Thanks,
After some detailed reading into many debezium topics, i was able to solve this by setting the REPLICA IDENTITY to FULL. Once I did this, on updates I was able to see the update messages and consume them.
I think the reason is this:
If a table does not have a primary key, the connector does not emit UPDATE or DELETE events for that table. For a table without a primary key, the connector emits only create events. Typically, a table without a primary key is used for appending messages to the end of the table, which means that UPDATE and DELETE events are not useful.
reference resources
Using soft-deletes in Laravel 5.4. When I try to create an record that already has been created but soft-deleted I get the message "The xxx has already been taken". What is the best way to be able handle the event when
a user attempts to save a record that has already has been soft deleted?
I have been trying to capture this event in the store method of the controller but the store method does not get called if the record already exists - AFAIK.
In my use case I have radios that can be associated to only one user at a time but can be unassigned e.g. soft-deleted and then reassigned to another user in the future.
You can restore() to restore a soft deleted model:
App\User::withTrashed()->where('id', $user_id)->restore();
Restoring Soft Deleted Models
I'm creating a simple form that stores entered data in an extremely simple Oracle database table via a Java Servlet using JDBC. That table is using the email address as a primary key. If a user submits a form multiple times with the same email address, the execute function fails and throws a SQLException. The exception's string is the following:
java.sql.SQLException: ORA-00001: unique constraint (...removed...) violated
In this scenario, I would like to catch this exception and deal with it by telling the user that the form cannot be submitted multiple times with the same email address. What is the proper way to handle ORA-00001 separately and differently from any of the other SQLExceptions that can be thrown by execute? A string compare could obviously work here, but that seems like a poor solution.
If you don't need to be DBMS independent use SQLException.getErrorCode()
It returns the vendor specific numeric error code. For ORA-0001 this would be 1