Django同名应用名称冲突:二次创建polls应用报错
Hey there! Sorry to hear you hit a snag when restarting your Django project—let's break down what might be going on and fix it step by step.
Since you're restarting after deleting your initial project files, the error is almost certainly tied to leftover configurations or virtual environment quirks. Here are the most common fixes:
1. Wipe and rebuild your virtual environment
Old dependencies or cached project links in your virtual environment might be causing conflicts. Let's start fresh:
- Exit your current virtual environment first:
deactivate # Linux/macOS # Or for Windows: venv\Scripts\deactivate.bat - Delete the entire virtual environment folder (e.g., if yours is named
venv, just delete that folder) - Create a brand new virtual environment:
python -m venv venv - Activate the new environment:
# Linux/macOS source venv/bin/activate # Windows venv\Scripts\activate - Reinstall Django 2.0.2 and your required dependencies:
pip install django==2.0.2 - Create a new Django project, navigate into it, then try creating the polls app again:
django-admin startproject mysite cd mysite python manage.py startapp polls
2. Clear all leftover project files
If you only deleted visible files, hidden caches or configs might still linger:
- Delete the entire project directory completely (make sure you get rid of hidden folders like
__pycache__and files likedb.sqlite3) - Recreate your project from scratch using the steps above
3. Double-check your terminal path
It's easy to run the startapp command from the wrong directory! Make sure you're inside the folder that contains manage.py before executing:
# Verify you're in the right place by checking for manage.py ls # Linux/macOS dir # Windows # You should see manage.py listed here before running startapp
If you still get an error, drop the exact error message you're seeing—I can help you narrow it down further!
内容的提问来源于stack exchange,提问作者boymeetscode

