Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
In Django i want to display folders like google drive
This is my models.py. Displaying in folder structure format. class Folder(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='userfolders') folder = models.ForeignKey("self", on_delete=models.CASCADE,related_name='folders', null=True, blank=True) name = models.CharField(_('Folder Name'), max_length=70) class File(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='userfiles') folder = models.ForeignKey(Folder, on_delete=models.CASCADE, related_name='folderfiles') description = models.CharField(_('File Description'), max_length=70) location = models.FileField(_('Location of the File'), upload_to=file_location_path, null=True, blank=True) In the model as you can see i have folder with a self foreign key and file can be associated to a folder. Folder------+---Old Folder +---Folder1-+--Cats.jpg | +--File1.jpg +---File1.txt File Folder New -+---Puppy.jpg +---Dogs----+--Dog1.jpg +--Dog2.jpg +--Dog3.jpg | 1st level | 2nd level | 3rd level | How can i display the 1st level first and then if the user selects a folder then it should show its content. for example, if Folder New is selected then the users should see file named Puppy.jpg and folder named Dogs. Is this possible? -
Django Template CharField value check
I'm working on a Django Website and I'm trying to implement a very basic condition in my template, a null or empty field check in a ModelForm field. I'm not sure to do conditional display with divs but my first condition is always true. I only initialized the form and passed it to the template, so I don't undestand how my CharField can have a value, and I have the same problem for a FileField just below. models.py class Alias(models.Model): lexeme = models.ForeignKey(Lexeme, on_delete=models.CASCADE) alias_value = models.CharField(_("Value"), max_length=256, blank=True, null=True) language = models.CharField(_("Language"), choices=LANGUAGE_CHOICE, max_length=40, default='en') class Meta: verbose_name = "Alias" verbose_name_plural = "Aliases" ordering = ["alias_value"] def __str__(self): return self.alias_value views.py alias_form = AliasForm() template.html {% if alias_form.alias_value %} <div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo"> {% else %} <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo"> {% endif %} -
Sum of Subquery fields django
I have the following subquery: Subquery( ContestTaskRelationship.objects.filter( contest=contest, solved=OuterRef('id') ).values('cost').all() ) I need then to annotate my QuerySet with sum of cost values returned by each Subquery. How to do that? Wrapping the subquery in Sum returns only the first element of each subquery. -
python django what is the cause of this error
at first server is working but after shange in files this exceptions is come..... user@user:~/Desktop/mysite$ sudo python manage.py runserver Performing system checks... Unhandled exception in thread started by Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run self.check(display_num_errors=True) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check include_deployment_checks=include_deployment_checks, File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks new_errors = check(app_configs=app_configs) File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 10, in check_url_config return check_resolver(resolver) File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 19, in check_resolver for pattern in resolver.url_patterns: File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in get res = instance.dict[self.name] = self.func(instance) File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in get res = instance.dict[self.name] = self.func(instance) File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module return import_module(self.urlconf_name) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/home/user/Desktop/mysite/mysite/urls.py", line 22, in url(r'^webapp/', include('webapp.urls')), File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/init.py", line 52, in include urlconf_module = import_module(urlconf_module) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/home/user/Desktop/mysite/webapp/urls.py", line 1, in from django.conf.urls import urls ImportError: cannot import name urls -
Writing my first Django app
I am trying my hand at learning Django and trying out the step-by-step tutorial at https://docs.djangoproject.com/en/2.0/intro/tutorial03/. I have complete the app (well, till the Part 7) and is working as expected (and has been explained in the tutorial). The only problem (so far) I am facing is when I am trying to navigate from the "Admin" page to the linked page "VIEW SITE" when I am being presented with "Page not found (404)" error. An image is being attached to make the situation clearer. The link is pointing to "http://127.0.0.1:8000/" whereas it should be pointing to "http://127.0.0.1:8000/polls/". When I add the missing part of the path (manually) in the address bar the correct page (as expected) is presented. I have tried to search on this as well as many other forums but could not get the right solution. I am using Django 2.0.6 and Python 3.6.4 on mac sierra. Shall be grateful for a lead on this. Thanks mysite/urls.py from django.contrib import admin from django.urls import include, path urlpatterns = [ path('polls/', include('polls.urls')), path('admin/', admin.site.urls), ] mysite/polls/urls.py from django.urls import path from . import views app_name = 'polls' urlpatterns = [ path('', views.IndexView.as_view(), name='index'), path('<int:pk>/', views.DetailView.as_view(), name='detail'), path('<int:pk>/results/', views.ResultsView.as_view(), name='results'), โฆ -
Django Unit Testing That Needs OAuth Authentication
I have a Django project that uses Gmail API to send bulk emails. Users can create campaign emails and send them to multiple contacts. If a contact answer to any of the emails in a campaign then that contact should no longer receive emails from that campaign email. I want to add unit tests for this feature and I don't know what approach to use because I need to authorize one Gmail account first and only after that use that account to send the campaign email. Also I would like to test the replies of that campaign, which means that I need to authorize a new Gmail account that will be used to send the reply. So this is what I plan to do: 1. Authorize two Gmail accounts manually. 2. Inside the tests I will search for the first two Gmail accounts from the database and use one of them to send the campaign email and another one to reply to an email. The only problem is that I am not sure that this approach is the best, this is why I am asking here, maybe someone has a better idea. Thank you! -
The date2 is not displayed when I'm using __range
I'm using __range in my view to display all dates between the first date and the second like: elif date2 > date1: reservations = reservations.filter(Q(reserved_on__range=(date1, date2))) The both variables (date1 and date2) are date field forms (<input type="date"... />). The problem is that all dates are displayed except date2 (cf. screenshot). I can't do date2+1 because it's not an integer so what should I do? Thanks. -
'is_superuser' is an invalid keyword argument for this function
I used Django restframework. To implement customize user model, I use AbstractBaseUser. models.py code is below. [models.py] from django.db import models from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.utils import timezone class UserManager(BaseUserManager): use_in_migrations = True def _create_user(self, username, email, password, is_staff, is_admin, is_active, is_superuser, **extra_fields): now = timezone.now() if not username: raise ValueError('Username must be set') email = self.normalize_email(email) user = self.model(username=username, email=email, is_staff=is_staff, is_admin=is_admin, is_active=is_active, is_superuser=is_superuser, date_joined=now, **extra_fields) user.set_password(password) user.save(self._db) return user def create_user(self, username, email, password, **extra_fields): return self._create_user(username, email, password, False, False, True, False, **extra_fields) def create_superuser(self, username, email, password, **extra_fields): return self._create_user(username, email, password, True, True, True, True, **extra_fields) class User(AbstractBaseUser): USER_TYPE_CHOICES = ( ('django', 'Django'), ('facebook', 'Facebook'), ('google', 'Google') ) user_type = models.CharField( max_length=20, choices=USER_TYPE_CHOICES, default='Django' ) email = models.CharField(max_length=100, null=False) username = models.CharField(max_length=20, unique=True) phone = models.CharField(max_length=12) # Default Permission is_staff = models.BooleanField(default=False) is_admin = models.BooleanField(default=False) is_active = models.BooleanField(default=False) is_superuser = models.BooleanField(default=False) date_joined = models.DateTimeField(auto_now_add=True) USERNAME_FIELD = 'username' objects = UserManager() REQUIRED_FIELDS = ['email'] def get_full_name(self): pass def get_short_name(self): pass @property def is_superuser(self): return self.is_admin @property def is_staff(self): return self.is_admin def has_perm(self, perm, obj=None): return self.is_admin def has_module_perms(self, app_label): return self.is_admin @is_staff.setter def is_staff(self, value): self._is_staff = value When I create super user, It โฆ -
i have a modal issue when i need to autofill the field user in the model in django?
models field I have a modal name pages which have following fields ,when i create a object through the admin i need to autofill the field user in the model . Now when a user login,it shows all users as in the user attribute values. I only want the user who logged in.how can i done this? class Pages(models.Model): CHOICE_TYPE = (('notice', 'Notice'), ('page', 'Page')) title = models.CharField(max_length=50) type = models.CharField(max_length=50, choices=CHOICE_TYPE, default='notice') slug = models.SlugField() content = RichTextField(null=True,blank=True) user = models.ForeignKey(User, on_delete=models.CASCADE) date = models.DateField(auto_now_add=True) class Meta: verbose_name_plural = "Page" -
Changing Queryset sent from Views.py in Django to Jquery Ajax call
Hi i am trying to convert my queryset to objects so that i can populate my dynamic table. $(document).ready(function(){ $('#ReusableDpuId').on('change',function(){ var catid; catid = $(this).find(':selected').attr("data-catid"); alert(catid); $.ajax({ type: 'GET', url: "InputColumns", data:{catid:catid}, success: function (data) { alert (data); ;}, }); }) }); in this code, when i get the alert(data) ,i get <QuerySet [<Input: Input object (5)>, <Input: Input object (6)>, <Input: Input object (7)>]> i want to convert them to the individual ids. so that i can make a dynamic table. PS- is there a way to directly make a table in the html from these querysets? -
Why is my website not picking up changes to staticfiles?
I am making changes to content in the staticfiles folder after python manage.py collectstatic was invoked in a development environment. The website showing the content does not show the changes (to javascript files) and I dont know why. This problem is important to me because I am attempting to decouple my javascript preprocessing from the django framework, in favour of os.system("grunt development" + " --gruntfile ../grunt/grunt_webjob.js"). My settings.STATICFILES_STORAGE option is set to 'django.contrib.staticfiles.storage.StaticFilesStorage'. If this were instead set to django.contrib.staticfiles.storage.CachedStaticFilesStorage, I would expect such a result, yet this is not the case. settings.CACHES is as follows: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'TIMEOUT': '30' } } I dont know if it is related to the problem. -
Using locally stored images in Django template
I have a image stored on my desktop and i want to give absolute path for the image in my django template without including the image in static folder of my django procject. For now I have tried is : <img id="logo" src="/C:/Users/Syama/Desktop\currentValueIcon.png"/> But this doesn't work. Any suggestions on how to achieve this ? -
{% block something %} always being displayed despite being False in an if-statement
I have two types of blog articles. Regular blog articles, and translation articles. They both have different html markup. I have a boolean variable translation_bool in my models to check if it is a translation article or not. If it is I want it to display my {% block translation %} and if not {% block translation %}. It worked with plain html code and not using html tags. But I had so much reusable code that it got troublesome to manage. So my question is: why is this happening despite it being inside of an if statement. Article template: {% extends "base_generic.html" %} {% load static %} {% block js %}...{% endblock %} {% if blogpost.translation_bool == True %} {% block translation %}....{% endblock %} {% else %} {% block content %}...{% endblock %} {% endif %} {% block sidebar %}....{% endblock %} In Base Generic Template: <div class="row"> <div class="col-md-1"></div> <div class="col-md-8"> {% block content %}{% endblock %} {% block translation %}{% endblock %} </div> <div class="col-md-3"> {% block social_media %}...{% endblock %} {% block sidebar %}...{% endblock %} </div> </div> </body> -
Complicated query in django orm
I'm trying to make a complicated annotation over through model if ManyToMany relationship in django. My database schema is roughly the following: class Contest(models.Model): tasks = models.ManyToManyField('Task', related_name='contests', blank=True, through='ContestTaskRelationship') participants = models.ManyToManyField('User', related_name='contests_participated', blank=True) class Task(models.Model): pass class ContestTaskRelationship(models.Model): contest = models.ForeignKey('Contest', on_delete=models.CASCADE, related_name='contest_task_relationship') task = models.ForeignKey('Task', on_delete=models.CASCADE, related_name='contest_task_relationship') solved = models.ManyToManyField('User', related_name='contest_task_relationship', blank=True) cost = models.IntegerField(default=0) tag = models.ForeignKey('TaskTag', on_delete=models.SET_NULL, related_name='contest_task_relationship', null=True, blank=True) I have a contest object and need to load its participants, each annotated with sum of cost fields of through model objects corresponding to contest if participant is in solved m2m relationship of that through model object. I have no idea how to make such a complicated annotation. I tried coming up something with Subquery, but had no luck. Any ideas how to do that? -
FOREIGN KEY constraint failed
Using Django 2.0.5 I've encountered a problem with admin panel. Adding data through admin panel gives 'django.db.utils.IntegrityError: FOREIGN KEY constraint failed' error. In model there is no foreign key that this could refer to. models.py class JobTitle(models.Model): job_title = models.CharField(max_length=200) admin.py class JobTitleAdmin(admin.ModelAdmin): list_display = ['job_title',] admin.site.register(JobTitle, JobTitleAdmin) Adding the same data with PUSH from frontend is working, only from admin panel gives this error. -
Django filler not working. ImportError: cannot import name mixins
Im calling migrate on my manage.py but it is not working. I am running Ubuntu 18.04 here is the error:" Traceback (most recent call last): File "/snap/pycharm-professional/68/helpers/pycharm/django_manage.py", line 52, in <module> run_command() File "/snap/pycharm-professional/68/helpers/pycharm/django_manage.py", line 46, in run_command run_module(manage_file, None, '__main__', True) File "/usr/lib/python2.7/runpy.py", line 188, in run_module fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code mod_name, mod_fname, mod_loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/jre/PycharmProjects/autda_emp/manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute django.setup() File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models() File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/filer/models/__init__.py", line 3, in <module> from .clipboardmodels import * # flake8: noqa File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/filer/models/clipboardmodels.py", line 9, in <module> from . import filemodels File "/home/jre/PycharmProjects/autda_emp/venv/local/lib/python2.7/site-packages/filer/models/filemodels.py", line 16, in <module> from . import mixins ImportError: cannot import name mixins here is my pip freeze: Django==1.11.13 django-filer==1.3.1 django-js-asset==1.1.0 django-mixins==0.0.10 django-mptt==0.8.7 django-polymorphic==1.3.1 django-suit==0.3a3 easy-thumbnails==2.5 Pillow==5.1.0 psycopg2==2.6.1 pytz==2018.4 Unidecode==0.4.21 I have not done much aside of creating a project and installing the packages following directions in the documentation. if needed here is โฆ -
Django- Get data of another child in a template
I'm making a Board which can write comments. All functions work well. But the only thing I need is displaying profile of the author of the comment. {{ board.title }} {{ board.text }} {% for comment is context.commentmodel_set.all %} {{ comment.comment }} {{ comment.whose.profile??? }} <- ???? {% endfor %} The image for reference is attached below. Thank you. -
Django filter with keyword arguments and a NOT condition
I've got these keyword arguments that I pass into a Django filter() - kwargs = {'field_1': val_1, 'field_2': val_2} However I also want to pass in a NOT check, for example, field_3 is NOT val_3. I know I can do that using a Q object but I would like to know if I can somehow accomplish that using a keyword argument. The reason I'm asking is that there is already a code written by one of my colleagues that constructs the kwargs parameters according to passed-in arguments, and filters the Django queryset. I would like to use the same code without having to write a separate one if I can help it. Thanks! -
Django - provide changed path for settings.py
How is it possible to change the django project root directory? For easier collaboration I changed the directory structure of an existing django-project like this: โโโ docs โโโ manage.py โโโ requirements.txt โโโ static โ โโโ my_app โ โโโ css โ โโโ fonts โ โโโ img โ โโโ js โโโ templates โ โโโ my_app โโโ proj_name โโโ apps โ โโโ my_app โ โฎ โ โโโ views.py โโโ settings โ โโโ base.py โโโ urls.py โโโ wsgi.py Changed BASE_DIR in settings-file like that BASE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '..') Using manage.py throws errors python manage.py makemigrations django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. To figure out the problem more exactly I ran check which actually throws a different error python manage.py check django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty. Before changing the directory-structure the project worked. Directory restructuring inspired by Best practice for Django project working directory structure -
Heroku doesn't collect my staticfiles
I am sorry for my poor English, but my country doesn't have many python engineer, so let me ask here, and I hope you help me. I deployed my app which was made with Django on heroku, and that was fine. at that time, all staticfiles were loaded. But, when I introduced cloudinary, which is add-on of heroku, to post images in my homepage, my app became disable to load my staticfiles like this. Counting objects: 42, done. Delta compression using up to 4 threads. Compressing objects: 100% (41/41), done. Writing objects: 100% (42/42), 3.89 KiB | 398.00 KiB/s, done. Total 42 (delta 32), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Python app detected remote: -----> Installing requirements with pip remote: remote: -----> $ python manage.py collectstatic --noinput remote: 0 static files copied to '/tmp/build_myappservercode/staticfiles'. remote: remote: -----> Discovering process types remote: Procfile declares types -> web remote: remote: -----> Compressing... remote: Done: 56.4M remote: -----> Launching... remote: Released v31 remote: https://myappname.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done.. To https://git.heroku.com/myappname.git 2ba59f3..56178c8 master -> master It says that "0 static files copied to ~/staticfiles". when I run "heroku run python manage.py โฆ -
django form is invalid, how to use form.model
Common, we use form.save when form.is_valid is True. In my project, when form.is_valid is False, I need to save form.errors to errors which is one field belong to my model, then do form.save. there are some question: 1. which type of errors is good, char or jsonb or text 2. when form.is_valid is True, i use form.cleaned_data to instantiate the model,but when form.is_valid is False,how can i get the model instance -
Custom Filter Tag inside For in Template
Im writing a report page, and i need to display data from one table related with another table (foreignkeys...), but when iuse my filter tag to filter one queryset and bring me all data filtered by the element id of my forloop i get errors Models class Foo(models.Model): ... class Bar(models.Model): foo = models.ForeignKey(Bar) ... TemplateTag from django import template from .models import Foo, Bar register = template.Library() @register.filter def get_bar_from_foo(self) return Bar.objects.filter(foo__id=self.id) HTML {% for fo in foos %} {% with bars=fo|get_bar_from_foo %} {% for bar in bars %} {{ bar }} {% endfor %} {% endwith %} {% endfor %} -
Sending Django push notification to APNS and FCM gets protocol error
In my server I have django-push-notifications==1.6.0 and there is this strange error: Sending a push to FCM with package version 1.6.0 works fine, but with APNs sending a push I get this error (Traceback): Traceback (most recent call last): File "<console>", line 1, in <module> File "/virtpy/myapp/local/lib/python2.7/site-packages/push_notifications/models.py", line 167, in send_message **kwargs File "/virtpy/myapp/local/lib/python2.7/site-packages/push_notifications/apns.py", line 113, in apns_send_message certfile=certfile, **kwargs File "/virtpy/myapp/local/lib/python2.7/site-packages/push_notifications/apns.py", line 94, in _apns_send **notification_kwargs File "/virtpy/myapp/local/lib/python2.7/site-packages/apns2/client.py", line 53, in send_notification stream_id = self.send_notification_async(token_hex, notification, topic, priority, expiration, collapse_id) File "/virtpy/myapp/local/lib/python2.7/site-packages/apns2/client.py", line 78, in send_notification_async stream_id = self._connection.request('POST', url, json_payload, headers) File "/virtpy/myapp/local/lib/python2.7/site-packages/hyper/http20/connection.py", line 281, in request self.endheaders(message_body=body, final=True, stream_id=stream_id) File "/virtpy/myapp/local/lib/python2.7/site-packages/hyper/http20/connection.py", line 555, in endheaders stream.send_headers(headers_only) File "/virtpy/myapp/local/lib/python2.7/site-packages/hyper/http20/stream.py", line 98, in send_headers conn.send_headers(self.stream_id, headers, end_stream) File "/virtpy/myapp/local/lib/python2.7/site-packages/h2/connection.py", line 839, in send_headers self.state_machine.process_input(ConnectionInputs.SEND_HEADERS) File "/virtpy/myapp/local/lib/python2.7/site-packages/h2/connection.py", line 246, in process_input "Invalid input %s in state %s" % (input_, old_state) ProtocolError: Invalid input ConnectionInputs.SEND_HEADERS in state ConnectionState.CLOSED And now if I downgrade the package to django-push-notifications==1.4.1 APNs works fine and FCM won't work now getting this error: Invalid field name(s) for model GCMDevice: 'cloud_message_type'. Settings in server: PUSH_NOTIFICATIONS_SETTINGS = { "FCM_API_KEY": "[MY_FCM_KEY]", "APNS_CERTIFICATE": os.path.join(BASE_DIR, push_certificate), "APNS_TOPIC": "com.company.myapp", "GCM_ERROR_TIMEOUT": 60, } Any idea how to get both running? -
ModuleNotFoundError: No module named 'rango'
I am trying to use Python shell to import a model, getting error: ModuleNotFoundError: No module named 'rango' I've also noticed in my urls.py i am getting 'Unresolved Import: views' I think my project structure might be the cause of both errors, I used eclipse to create django project for the first time. I have added rango app in the installed apps in setting, just as: 'rango', HERE IS THE SCREEN FOR PROJECT STRUCTURE AND ERROR: https://imgur.com/a/Ppp87Q5 views.py from django.shortcuts import render from django.http import HttpResponse def index(request): context_dict = {'boldmessage': "Crunchy, creamy, cookie, candy, cupcake!" } return render(request, 'rango/index.html', context=context_dict) models.py from django.db import models class Category(models.Model): # Unique TRUE attr means the name must be unique - can be used as a primary key too! name = models.CharField(max_length=128, unique=True) def __str__(self): return models.Model.__str__(self) class Page(models.Model): category = models.ForeignKey(Category, on_delete=models.CASCADE) title = models.CharField(max_length=128) url = models.URLField() views = models.IntegerField(default=0) def __str__(self): return models.Model.__str__(self) class user_session(models.Model): userNAME = models.CharField(max_length=120, unique=True) addToCarts = models.IntegerField(default=0) def __str__(self): # __unicode__ on Python 2 return self.headlin -
I delete django migrations, but have some errors
i delete all migration files find . -path "*/migrations/*.py" -not -name "__init__.py" -delete find . -path "*/migrations/*.pyc" -delete then drop the database and create new, clear. But when i try to reate the initial migrations and generate the database schema: python manage.py makemigrations i have error django.db.utils.ProgrammingError: (1146, "Table 'buzz_local.api_userprofile' doesn't exist") why? i don't need any migration files, because we need to recreate current db