0

I have created a model named file. It was running well, then I created an element inside the class named set_user which gave an error. So, I removed it. But, I think it's not deleted my my database as I am getting this error while trying to migrate:

Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/usr/lib/python3/dist-packages/django/core/management/init.py", line 363, in execute_from_command_line utility.execute() File "/usr/lib/python3/dist-packages/django/core/management/init.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/usr/lib/python3/dist-packages/django/core/management/commands/makemigrations.py", line 96, in handle loader = MigrationLoader(None, ignore_no_migrations=True) File "/usr/lib/python3/dist-packages/django/db/migrations/loader.py", line 52, in init self.build_graph() File "/usr/lib/python3/dist-packages/django/db/migrations/loader.py", line 203, in build_graph self.load_disk() File "/usr/lib/python3/dist-packages/django/db/migrations/loader.py", line 114, in load_disk migration_module = import_module("%s.%s" % (module_name, migration_name)) File "/usr/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked
File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/home/hashir/website/one/migrations/0017_auto_20171222_2108.py", line 11, in class Migration(migrations.Migration): File "/home/hashir/website/one/migrations/0017_auto_20171222_2108.py", line 21, in Migration field=models.ForeignKey(default=one.models.file.set_user, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), AttributeError: type object 'file' has no attribute 'set_user'

Here's models.py:

from django.db import models
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User

class file(models.Model):
    title = models.CharField(max_length=250)
    FILE_TYPE_CHOICES = (
        ('audio','Audio'),
        ('games','Games'),
        ('videos','Videos'),
        ('applications','Applications'),
        ('books','Books/Docs'),
        ('others','Others')
        )
    file_type = models.CharField(max_length=12,choices=FILE_TYPE_CHOICES,default='others')
    description = models.TextField(max_length=6000)

    def get_absolute_url(self):
        return reverse('one:user')

    def __str__(self):
        return self.title
3
  • 1
    You haven't included enough information. Please show the full traceback. Commented Dec 22, 2017 at 22:11
  • Mind the case of your class python.org/dev/peps/pep-0008/#class-names File instead of file. Commented Dec 22, 2017 at 22:19
  • @Alasdair I've included Commented Dec 22, 2017 at 22:48

1 Answer 1

0

Just delete migrations folder from the project and apply the migrations again. Then run these 3 commands:

python manage.py migrate yourapp zero
python manage.py makemigrations yourapp
python manage.py migrate yourapp
Sign up to request clarification or add additional context in comments.

1 Comment

This might have worked in your case, but it won't work in all cases. Think carefully before you delete migrations that you have already applied. You risk your database and migrations getting out of sync, which can be very hard to fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.