Also habe ich mich mithilfe dieser Anleitung https://www.crunchydata.com/blog/extend ... toonefield daran versucht, mithilfe eines OneToOne Feldes den "eingebauten" user mit meinem "Schueler"model zu verbinden. Auch das bekomme ich nicht hin. Ich habe sowohl die Daten in "Schueler" gelöscht als auch die user in der django.contrib.auth.models und dann in meinem model "Schueler" ergänzt:
Code: Alles auswählen
class Schueler(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True,)
nachname = models.CharField(max_length=20)
vorname = models.CharField(max_length=20)
Code: Alles auswählen
It is impossible to add a non-nullable field 'user' to schueler without specifying a default. This is because the database needs something to populate existing rows.
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit and manually define a default value in models.py.
Der Schreiber der obengenannten Anleitung hatte auch das Problem. Er schreibt:
Könnt ihr mir da weiterhelfen?However, when I tried to run the migration, it errored out because of the existing person_id primary key in the database, instead of just deleting that primary key and creating a new one with user like I had thought would happen. After some trial and error I decided to just remove person_id directly in Postgres:
DROP SEQUENCE person_person_id_seq;
ALTER TABLE person DROP COLUMN person_id;