sei-ec-remote / project-4-issues

Open an issue to receive help on project 4
0 stars 0 forks source link

Migration Error #128

Closed LarryMays92 closed 2 years ago

LarryMays92 commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

Django

What's the problem you're trying to solve?

Trying To Make a New Migration

Post any code you think might be relevant (one fenced block per file)

from django.db import models

from django.contrib.auth.models import User

# Create your models here.
class Student(models.Model):
    name = models.CharField(max_length=100)
    classification = models.CharField(max_length=100, blank=False, default= 'Freshman') 
    current_grade = models.CharField(max_length=100, default= '20')

    def __str__(self):
        return self.name

class Course(models.Model):
    name = models.CharField(max_length=100)
    time = models.CharField(max_length=100, default= '8:00am- 9:15am')
    start = models.CharField(max_length=100, blank=False, default= '08-15-2022')
    end = models.CharField(max_length=100,blank= False, default= '12-15-2022')
    students = models.ManyToManyField(Student, 
    through = 'Enrollment')
    user = models.ForeignKey(User, on_delete=models.CASCADE, default = False)

    def __str__(self):
        return self.name

class Enrollment(models.Model):
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    start = models.CharField(max_length=100, blank=False, default= '08-15-2022')
    end = models.CharField(max_length=100,blank= False, default= '12-15-2022')
    current_grade = models.CharField(max_length=1, blank=True, null= True)
    instructor: models.CharField(max_length=100)
    students = models.ForeignKey(Student, on_delete=models.CASCADE)
    class Meta:
        unique_together= [['students','course']]

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

schema_editor.alter_field(from_model, from_field, to_field) File "/Users/alexisdavenport/.local/share/virtualenvs/django-env-DblZDiee/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 778, in alter_field raise ValueError( ValueError: Cannot alter field main_app.Course.students into main_app.Course.students - they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields)

What is your best guess as to the source of the problem?

there is an issue with my many to many field

What things have you already tried to solve the problem?

research, questions, etc

Paste a link to your repository here https://github.com/LarryMays92/MaysUniversity

kestler01 commented 2 years ago

curious, have we tried removing all the current migration files and making a new one ?

LarryMays92 commented 2 years ago

delete all the migrations except the first one like we did yesterday?

kestler01 commented 2 years ago

even get rid of that one so we make 1 'super all encompassing' migration

LarryMays92 commented 2 years ago

so delete all of them?

kestler01 commented 2 years ago

yes

LarryMays92 commented 2 years ago

its still showing them when i run show migrations do i need to drop db?

kestler01 commented 2 years ago

yes

LarryMays92 commented 2 years ago

heyyyyyyy that was it i didnt drop db though but will i need to create superuser maybe?

kestler01 commented 2 years ago

if you didn't drop the database you should still have your superuser

kestler01 commented 2 years ago

Note, that we only ever want to do this in a development setting at relatively early stages of a project - because we can lose all of our data in the db and not have the correct way to rebuild it.

LarryMays92 commented 2 years ago

ok but i think i had dropped my db last night so i gotta do the superuser thing again it was so broke i couldnt get my admin page up before hopefully i wont have to migrate any more though

LarryMays92 commented 2 years ago

i can access my admin but i cant go to any of the models and they added in my admin.py

LarryMays92 commented 2 years ago

ProgrammingError at /admin/main_app/student/ column main_app_student.current_grade does not exist LINE 1: ...ent"."name", "main_app_student"."classification", "mainapp...

gettting this on the models

LarryMays92 commented 2 years ago

with self.db.wrap_database_errors: File "/Users/alexisdavenport/.local/share/virtualenvs/django-env-DblZDiee/lib/python3.10/site-packages/django/db/utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/Users/alexisdavenport/.local/share/virtualenvs/django-env-DblZDiee/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: column main_app_student.current_grade does not exist LINE 1: ...ent"."name", "main_app_student"."classification", "mainapp...

and this in terminal

kestler01 commented 2 years ago

which zoom room are you in ?

LarryMays92 commented 2 years ago

finna hop in one

LarryMays92 commented 2 years ago

room 22

LarryMays92 commented 2 years ago

we deleted migrations and dropped db created db added superuser and its working now !!!!!!!!!!! DREWSKI THE GOAT