Using foreign Key

Hello guys,
I have a model College and a model Alumini. And now what I want to make is for the alumini registeration I want a list of colleges to be selected from the dropdown menu.I have done the coding part but somehow it is not working .Here are the models

class Alumini(models.Model):
    user=models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True)
    college=models.ForeignKey('College',on_delete=models.CASCADE)
    def __str__(self):
        return self.user.username

class College(models.Model):
    user=models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True)
    def __str__(self):
        return self.user.username

And here is the form for alumini register

class AluminiSignUpForm(UserCreationForm):
    college_list=College.objects.all()
    college= forms.CharField(label='What is your college?', widget=forms.Select(choices=college_list))
    class Meta(UserCreationForm.Meta):
        model = User

    @transaction.atomic
    def save(self):
        user = super().save(commit=False)
        user.is_alumini= True
        user.save()
        alumini = Alumini.objects.create(user=user)
        alumini.college.add(*self.cleaned_data.get('college'))
        return user

I have done python manage.py makemigrations app_name but when I’m trying to do python manage.py migrate.It is showing the following error.

Operations to perform:
  Apply all migrations: Users, admin, auth, contenttypes, sessions
Running migrations:
  Applying Users.0004_alumini_college...Traceback (most recent call last):
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\__init__.py", line 1774, in get_prep_value        
    return int(value)
ValueError: invalid literal for int() with base 10: 'Select'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards     
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\operations\fields.py", line 104, in database_forwards
    schema_editor.add_field(
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 328, in add_field
    self._remake_table(model, create_field=field)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 189, in _remake_table
    self.effective_default(create_field)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 303, in effective_default        
    return field.get_db_prep_save(self._effective_default(field), self.connection)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 971, in get_db_prep_save        
    return self.target_field.get_db_prep_save(value, connection=connection)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 971, in get_db_prep_save        
    return self.target_field.get_db_prep_save(value, connection=connection)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\__init__.py", line 823, in get_db_prep_save       
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\__init__.py", line 2388, in get_db_prep_value     
    value = self.get_prep_value(value)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\__init__.py", line 1776, in get_prep_value        
    raise e.__class__(
ValueError: Field 'id' expected a number but got 'Select'.

Is the correct way to create what i want to do o any other easy way is there outhere .
And how can this issue be resolved.
Please help me in solving this issue.
Thank you,

There are a couple of issues here:

The choices parameter in the Select constructor needs to be a list of either the choices or 2-tuples representing the pair (value, display), not a queryset.

Each instance of Alumini is only related to one college, and the field college is not null - that means you need to assign that field when you create the instance.
You’ll want something closer to:

alumini = Alumini(user=user, college=self.cleaned_data['college'])
alumini.save()

The add method only applies to the “set” side of a ManyToOne (or either side of a ManyToMany) relationship.

Ken

Thank you sir, I made the changes and now the form looks like this

class AluminiSignUpForm(UserCreationForm):
    colleges = forms.ModelChoiceField(
        queryset=College.objects.all(),
        required=True
    )

    class Meta(UserCreationForm.Meta):
        model = User

    @transaction.atomic
    def save(self):
        user = super().save(commit=False)
        user.is_alumini= True
        user.save()
        alumini = Alumini(user=user, college=self.cleaned_data['colleges'])
        alumini.save()
        return user

But I’m not able to register the alumini nor the college registration is working now .When I’m trying to register and after filling the details and clicking register .It is not registering me.And when I’m trying to create a alumini form admin page it is showing the following error


So how can this be resolved

Sir,I’m really thankful to the community here for giving the instant response on the issues

After making all your changes, did you do a makemigrations / migrate?

Also, it’s likely to be more helpful if you captured the complete stack dump from your console session rather than this partial screen capture.

Finally, to minimize the amount of code that you need to post here, let’s address just one issue at a time.

The first issue you’ve mentioned is that the college registration isn’t working. (If you don’t have any colleges, the Alumini registration isn’t going to work.)

What’s the specific problem you’re having with college registration? We’re going to need to see the form you’re using for that, the view that is handling the form, and any errors being shown in the console when you try to add a college.

Yes sir, I have done the makemigrations but when I’m trying to do migrate the following error is coming

PS C:\Users\mahanth kumar\mini_project\AluminiSystem> python manage.py migrate                
Operations to perform:
  Apply all migrations: Users, admin, auth, contenttypes, sessions
Running migrations:
  Applying Users.0002_auto_20201028_0728...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)      
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 229, in apply_migration
    migration_recorded = True
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 35, in __exit__
    self.connection.check_constraints()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 343, in check_constraints
    raise IntegrityError(
django.db.utils.IntegrityError: The row in table 'Users_alumini' with primary key '8' has an invalid foreign key: Users_alumini.college_id contains a value 'college_id' that does not have 
a corresponding value in Users_college.user_id.

I have solved the issue of collegeregisteration and now I’m able to register and login through college.
But I’m unable to register as a alumini and it is shown in the alumini registeration page as follows:

Now the form that is used for alumini registration form is

class AluminiSignUpForm(UserCreationForm):
    colleges = forms.ModelChoiceField(
        queryset=College.objects.all(),
        required=True
    )

    class Meta(UserCreationForm.Meta):
        model = User

    @transaction.atomic
    def save(self):
        user = super().save(commit=False)
        user.is_alumini= True
        user.save()
        alumini = Alumini(user=user, college=self.cleaned_data['colleges'])
        alumini.save()
        return user

The view that is handling the alumini register is

def alumini_register(request):
    if request.method !='POST':
        form=AluminiSignUpForm()
    else:
        form=AluminiSignUpForm(data=request.POST)

        if form.is_valid():
            new_user=form.save()
            # log the user in and then redirect to home page.
            authenticated_user=authenticate(username=new_user.username,password=request.POST['password1'])
            login(request,authenticated_user)
            return HttpResponseRedirect(reverse('Users:index'))
    context={'form':form}
    return render(request,'Users/alumini_register.html',context)

And the problem which I’m getting while I’m trying to register a alumini is

[28/Oct/2020 06:46:02] "GET /alumini_register/ HTTP/1.1" 200 1865
[28/Oct/2020 06:46:51] "POST /alumini_register/ HTTP/1.1" 200 1964
Internal Server Error: /alumini_register/
Traceback (most recent call last):
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 413, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such column: college_id

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\mahanth kumar\mini_project\AluminiSystem\Users\views\classroom.py", line 112, in alumini_register
    new_user=form.save()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "C:\Users\mahanth kumar\mini_project\AluminiSystem\Users\forms.py", line 36, in save   
    alumini.save()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\base.py", line 753, in save
    self.save_base(using=using, force_insert=force_insert,
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\base.py", line 790, in save_base
    updated = self._save_table(
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\base.py", line 872, in _save_table
    updated = self._do_update(base_qs, using, pk_val, values, update_fields,
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\base.py", line 926, in _do_update
    return filtered._update(values) > 0
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\query.py", line 803, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\sql\compiler.py", line 1522, in execute_sql
    cursor = super().execute_sql(result_type)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\sql\compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 98, in execute
    return super().execute(sql, params)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)       
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 413, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: college_id
[28/Oct/2020 06:47:38] "POST /alumini_register/ HTTP/1.1" 500 149200

And the alumini model is as follows:

class Alumini(models.Model):
    user=models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True)
    college=models.ForeignKey('College',on_delete=models.CASCADE,default=1)
    def __str__(self):
        return self.user.username

So it showing the following exception when I’m trying to register as a alumini:

Thank you,sir

Can you post your UserCreationForm? (Or are you using the Django default UserCreationForm?) Since your AluminiSignUpForm inherits from that, that’s also involved here.

So far, I’m unable to reproduce your symptoms. Have you done a makemigrations / migrate after your most recent set of changes?

I’m using django’s default UserCreationForm .
I have deleted all the previous migrations folder and db.sqlite and again freshly now did a makemigrations then it came like this

PS C:\Users\mahanth kumar\mini_project\AluminiSystem> python manage.py makemigrations Users   
Migrations for 'Users':
  Users\migrations\0001_initial.py
    - Create model College
    - Create model User
    - Create model Topic
    - Create model Entry
    - Create model Alumini

Now when I’ve done python manage.py migrate, the following error is showing

PS C:\Users\mahanth kumar\mini_project\AluminiSystem> python manage.py migrate
Operations to perform:
  Apply all migrations: Users, admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying Users.0001_initial...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)      
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)      
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\operations\models.py", line 92, in database_forwards
    schema_editor.create_model(model)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 322, in create_model
    sql, params = self.table_sql(model)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 159, in table_sql
    definition, extra_params = self.column_sql(model, field)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 212, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 1004, in db_parameters
    return {"type": self.db_type(connection), "check": self.db_check(connection)}
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 1001, in db_type
    return self.target_field.rel_db_type(connection=connection)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 897, in target_field
    return self.foreign_related_fields[0]
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 644, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\dja    return self.resolve_related_fields()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 936, in resolve_related_fields
    related_fields = super().resolve_related_fields()
  File "C:\Users\mahanth kumar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields\related.py", line 615, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'Users.user' cannot be resolved

Here is the migrationfile

rom django.conf import settings
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0012_alter_user_first_name_max_length'),
    ]

    operations = [
        migrations.CreateModel(
            name='College',
            fields=[
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='Users.user')),
            ],
        ),
        migrations.CreateModel(
            name='User',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
                ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
                ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
                ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
                ('is_alumini', models.BooleanField(default=False)),
                ('is_college', models.BooleanField(default=False)),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
                ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
            ],
            options={
                'verbose_name': 'user',
                'verbose_name_plural': 'users',
                'abstract': False,
            },
            managers=[
                ('objects', django.contrib.auth.models.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name='Topic',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('text', models.CharField(max_length=200)),
                ('date_added', models.DateTimeField(auto_now_add=True)),
                ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='Entry',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('text', models.TextField()),
                ('date_added', models.DateTimeField(auto_now_add=True)),
                ('topic', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Users.topic')),
            ],
            options={
                'verbose_name_plural': 'entries',
            },
        ),
        migrations.CreateModel(
            name='Alumini',
            fields=[
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='Users.user')),
                ('college', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='Users.college')),
            ],
        ),
    ]

THANK YOU

Is anyone here who can solve the issue

Look for anything anywhere in your code that is looking for a model named Users. (You didn’t include such a model in any of the code I see above - all your references are to User.)

I have fixed the error ,Thank you

Thank You for help me.