Does anyone know of any query to delete a member in Umbraco 8 using sql. I had created a member which is corrupt now and creating errors in backoffice, so i want to delete it
I assigned the wrong email address to a new user, so I recreated the user with the correct email address and ended up with a disabled user which never is going to be used. I noticed that you can only "disable" users in the Umbraco back office.
I managed to delete the user via some SQL statements.
But because of some foreign keys, it took some extra steps.
1: Look up all users and thus their respective ID
SELECT * FROM [yourDBname].[dbo].[umbracoUser]
selection umbracoUser
For example, you want to delete the user with id 4. In your case the corrupted member.
2: Delete the user with the respective id from the umbracoUserLogin table
DELETE FROM [yourDBname].[dbo].[umbracoUserLogin] WHERE userId = 4
3: Do the same thing for the umbracoUser2UserGroup
DELETE FROM [yourDBname].[dbo].[umbracoUser2UserGroup] WHERE userId = 1
4: Lastly delete the user from the umbracoUser table
DELETE FROM [yourDBname].[dbo].[umbracoUser] WHERE id = 4
Because of the foreign keys, you should delete user rows in this order ([umbracoUserLogin] -> [umbracoUser2UserGroup] -> [umbracoUser]) otherwise, you get an error that you can't delete the row because of the foreign key.
Related
I have a MVC-Project with a DB-First EDMX file from a production database.
Let's say table Person has an identity-column named ID.
I also have a copy of this database where I have turnd OFF the Identity-Option for the ID column. My goal is to synchronize data between these two databases.
To connect to each of these databases I use the same context-class with different connection-strings.
The problem with this is, that when I try to add a copy of a row from table Person from productionDB to my copyDB I get an error, because EntityFramework is trying to insert NULL for the ID column. I know that this is totally normal, because the EDMX-File has set identity to TRUE for the ID-column of table Person, but is there a way to programatically change this behaviour?
Context prod = new Context("ProductionConnectionString");
Context prodCopy = new Context("CopyConnectionString");
var prodEntity = prod.Person.First(); \\ RETURNS A PERSON WITH ID 1
prodCopy.Person.Add(prodEntity):
prodCopy.SaveChanges(); \\THIS WILL THROW AN EXCEPTION BECAUSE EF WILL REPLACE 1 WITH NULL BECAUSE IDENTITY OPTION
Any ideas?
Using Ruby on Rails I have generated a pins controller and would like to understand how the pin id works after destroying a pin.
The first pin I created has a pin id of 1, the second has a pin id of 2. After destroying the second pin and creating a new one, the last one I created has a pin id of 3.
Why doesn't the pin created after destroying the second pin have an id of 2? Is there a way to set it to that?
The ids of the database records are usually auto incremented if unless specified. That's why, everytime you delete a record and then create a new record, then the new record gets a next number as its id.
Yes, you can update the record if you want to set the id to something else.
For example, you have a Pin model which has id and name attributes.
You can create a pin like this:
pin = Pin.create(name: 'Pin1')
So, it will get id = 1. But, if you destroy this pin object and re-create another one in a similar fashion:
pin = Pin.create(name: 'Pin1')
it will get id = 2 and so on.
But, you can update it's id attribute if you want like this (Although, in real-life application you don't want to do that!):
pin.id = 1
pin.save
Now, it's id is 1 again.
So, theoretically it's possible, but you should not modify the database record IDs manually in a real-life application.
I am trying to make a Record Type that contains unique values, and would act as the target reference objects to another Record Type. For example, Record Type - Movies would contain unique list of movies submitted by users. And FavoriteMovies would contain a Users reference and a Movies reference. Users could select from a list of existing Movies, or add new ones to it.
The problem happens if I create a new Movies record, while another user creates a new record with the same name (after I retrieved the list of movies, but before I attempt to add a new one). The two new records are considered different records with different recordIDs. This means that once I saved the new one, there will be two instances of Movies with the save name.
I'm not able to find a way to perform a Save If Not Exists type operation to the Movies Record Type. I could do a save in the completionBlock of a query, but those two actions would not be an atomic transaction to guarantee uniqueness. As far as I know this is also the case with chaining CKQueryOperation with CKModifyRecordsOperation.
Is there a way to insert a record only if the value does not exists in a single transaction?
If I understood correctly your use case, you can make movieRecord.recordID.recordName the movie's name and use CKModifyRecordsOperation with savePolicy IfServerRecordUnchanged to effectively Save If Not Exists. It would then return an error that you can ignore if you try to save a record that already exists on the server:
let saveRecordsOperation = CKModifyRecordsOperation()
saveRecordsOperation.recordsToSave = [movieRecord]
saveRecordsOperation.savePolicy = .IfServerRecordUnchanged
With the savePolicy IfServerRecordUnchanged this operation will save a new Movie record if it doesn't exist yet on the server (Save If Not Exists) but will return the error below on any subsequent try to overwrite a Movie record that already exists on the server (provided it is not a newer modified version of a record that was fetched from the server):
<CKError 0x14d23980: "Server Record Changed" (14/2017); server message = "record to insert already exists">
You could deal with this conflict in the perRecordCompletionBlock but in your specific use case you can just do nothing about the conflict error so each Movie record will be the first saved record with that CKRecordID.
I am wondering if, in some hidden corner of the API I haven't yet run into, if there is a way to clone an existing record into a new one, so when saved it will have a new id assigned?
This is intended to be used on an event site I am writing, which will allow people to import from previous years, but copying it will allow updating the event description with new content.
You can use dup method for this.
Given object user1 of model User, you can do:
user2 = user1.dup
user2.save
Doing user2 = user1.dup clones user1 into user2, and user2 has no id, created_at and updated_at values assigned and it is treated as a new record.
I have two tables (users , messages) which there is many to many relationship for them.
i want to add new messages in message table and allocate massages to current users.
Also i insert data like below:
Message newMessage = Message.CreateMessage("MessageText", "DateTime");
newMessage.Users.Add(new User{..... });
context.SaveChange();
this code will execute a query which add a new user in users table while the users table has some specified users and i don't want to add new user but as i mentioned i want to add new messages in message table and allocate massages to current users.
how should i do that?
The problem is you are creating a new User object with an existing primary key. When SaveChanges() is called EF detects the changes of the entities its already tracking and new entities added. Since your new User object was not tracked by EF, it tries to insert it.
You need to explicitly tell EF that the created user is an existing one. To do that you need to attach it.
Message newMessage = Message.CreateMessage("MessageText", "DateTime");
var user = new User{ Id = "foo" };
context.Users.Attach(user);
newMessage.Users.Add(user);
context.SaveChange();