This
https://stackoverflow.com/questions/62726885/foreign-key-mismatch-comment-referencing-chellenge
seems to work, but now I am getting a slew of database table model errors.



On Wednesday, March 1, 2023 at 12:35:59 PM UTC-8 Michael Starr wrote:

> I even deleted the pet field from pet_photo and it still gives this error, 
> even after deleting the db.sqlite3 database and remigrating. Makes no sense 
> whatsoever. The error is now referencing something that is not even there!
> Michael
>
> On Wednesday, March 1, 2023 at 12:33:00 PM UTC-8 Michael Starr wrote:
>
>> I have an error when I migrate my models. makemigrations passes just 
>> fine, but upon migrate, it seems to think there is some error in the 
>> pet_photo class' pet parameter and the pet_photo class:
>> class Pet(models.Model):
>>     slug = models.SlugField(max_length = 5, primary_key = True, blank = 
>> True, null=False)
>>     name = models.CharField(max_length = 255, unique = False)
>>     id = models.CharField(max_length = 261, unique = True, default = uuid
>> .uuid1)
>>     animaltype = models.CharField(choices = ANIMALTYPE_CHOICES, 
>> max_length = 255, default="the one that barks")
>>     age = models.PositiveIntegerField()
>>     profile_photo = models.ImageField(blank = True)
>>
>>     def save(self, *args, **kwargs):  # new
>>         slug_save(self)
>>         get_ID(self)
>>         return super().save(*args, **kwargs)
>>
>>     def __str__(self):
>>         return self.name
>>
>> class PetPhoto(models.Model):
>>     slug = models.SlugField(max_length = 5, primary_key = True, blank = 
>> True, null=False)
>>     title = models.CharField(max_length = 255)
>>     id = models.CharField(max_length = 261, default=uuid.uuid1)
>>     pet = models.ManyToManyField(Pet, related_name="Pet_Photos")
>>     photo = models.ImageField(blank = False)
>>
>>     def save(self, *args, **kwargs):  # new
>>         slug_save(self)
>>         get_ID(self)
>>         return super().save(*args, **kwargs)
>>
>>     def __str__(self):
>>         return self.title
>>
>> I don't see what's wrong. I have a manytomany field where each photo is 
>> manytomany to any number of pets (I don't know the correct terminology for 
>> this, if someone could correct my grammar please do so). But so what? I 
>> have manytomanyfield in other area of models:
>>
>> class PetOwner(models.Model):
>>     slug = models.SlugField(max_length = 5, primary_key = True, blank = 
>> True, null=False)
>>     name = models.CharField(max_length = 255)
>>     id = models.CharField(max_length = 261, unique = True, default=uuid.
>> uuid1)
>>     age = models.PositiveIntegerField()
>>     location = models.CharField(max_length = 255)
>>     profile_photo = models.ImageField(blank = True)
>>     pets = models.ManyToManyField(Pet, related_name = "Owners")
>>
>>     def get_absolute_url(self):
>>         return reverse("owner_profile", kwargs={"slug": self.slug})  
>>
>>     def save(self, *args, **kwargs):  # new
>>         slug_save(self)
>>         get_ID(self)
>>         return super().save(*args, **kwargs)
>>
>>     def __str__(self):
>>         return self.name
>>
>> and no error ever.
>>
>> Most of the google search results say to delete the migration .pyc files 
>> under the migrations/ folder buuuuuut they don't seem relevant. It's just 
>> like, added this parameter, changed this variable. There's nothing that 
>> really points to the manytomany relationship between pet and pet_photo in 
>> there, is what I am saying. So I don't see how deleting them (after rolling 
>> back the migrations, of course--though I think it will automatically 
>> reconstruct them either way so you don't have to roll them back per se 
>> before deleting them) would do anything. I tried deleting the most recent 
>> three and redid the database migrations and nothing worked.
>>
>> I'm stuck on this one. Google is not being too useful.
>>
>> Any help is appreciated.
>>
>> Michael
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1461c3d0-f4ae-403e-8926-49f12cb47626n%40googlegroups.com.

Reply via email to