Method for producing an electrical machine which has a cast part comprising a metallic functional region that extends in a first direction from a first side to a second side of the cast part, wherein the cast part has a surrounding region which at least partially surrounds the functional region, wherein the second side is shaped by a final shaping which is surrounded by the surrounding region, wherein relative to the surrounding region the final shaping forms a depression on the first side and an elevation on the second side, wherein the electrical machine comprises a further component and a device for securing the further component against twisting, wherein the device comprises a connection between the functional region of the cast part and the further component, wherein the functional region is shaped by a friction-based process that uses a rotating tool having a cylindrical main part, characterised in that in the main part a cylindrical part as a pin having a cylindrical shape can be withdrawn into the main part in a direction or extended from the main part in a direction concentrically relative to the main part in a channel, wherein a cutting device is provided on the circumferential surface of the pin and has a cutting edge for metal-cutting work, such that in a second direction of rotation of the tool about its longitudinal axis metal-cutting work using the tool is made possible and in the opposite direction of rotation metal-cutting work using the cutting device is not made possible, wherein the cylindrical main part has a larger diameter than the pin, wherein the main part has a shoulder adjacent to the pin, wherein the method comprises the following steps: - bringing the tool into contact with the cast part for the purpose of shaping the functional region of the cast part, wherein the pin is withdrawn into the main part, wherein the tool rotates in the direction, whereby the material of the cast part is plasticised locally at a location of the functional region that is to be shaped, - extending and introducing the pin into the plasticised material as far as a surface of the further component, wherein the material of the cast part continues to be plasticised by the shoulder, - changing the direction of rotation of the tool after reaching the surface of the further component, - creating a recess by introducing the pin into the further component by means of metal-cutting work in the second direction of rotation while the shoulder continues to plasticise the material of the cast part, - withdrawing the pin by a defined amount after reaching a final position of the pin in the first direction, and - concurrently flowing the plasticised material of the cast part and some of the swarf that is present as a result of the metal-cutting work, under the influence of a compressive force brought about by the shoulder in the first direction, into a space of the recess that has been created, thereby producing a type of mixed structure or dispersion hardening. - bringing the tool into contact with the cast part for the purpose of shaping the functional region of the cast part, wherein the pin is withdrawn into the main part, wherein the tool rotates in the direction, whereby the material of the cast part is plasticised locally at a location of the functional region that is to be shaped, - extending and introducing the pin into the plasticised material as far as a surface of the further component, wherein the material of the cast part continues to be plasticised by the shoulder, - changing the direction of rotation of the tool after reaching the surface of the further component, - creating a recess by introducing the pin into the further component by means of metal-cutting work in the second direction of rotation while the shoulder continues to plasticise the material of the cast part, - withdrawing the pin by a defined amount after reaching a final position of the pin in the first direction, and - concurrently flowing the plasticised material of the cast part and some of the swarf that is present as a result of the metal-cutting work, under the influence of a compressive force brought about by the shoulder in the first direction, into a space of the recess that has been created, thereby producing a type of mixed structure or dispersion hardening.