Python 从GitHub克隆应用程序后如何修复不一致的迁移历史
我正在用《Django初学者手册》来学习Django。 我从GitHub克隆了一个存储库,其中包含一个网站的代码,该网站只允许用户创建帐户、登录和注销 这是存储库: 我的目标是使用这个网站,能够创建一个帐户,登录和注销它 我输入文件夹并在终端中运行以下命令:Python 从GitHub克隆应用程序后如何修复不一致的迁移历史,python,django,sqlite,github,django-models,Python,Django,Sqlite,Github,Django Models,我正在用《Django初学者手册》来学习Django。 我从GitHub克隆了一个存储库,其中包含一个网站的代码,该网站只允许用户创建帐户、登录和注销 这是存储库: 我的目标是使用这个网站,能够创建一个帐户,登录和注销它 我输入文件夹并在终端中运行以下命令: pipenv shell pipenv install python manage.py runserver Watching for file changes with StatReloader Performing system c
pipenv shell
pipenv install
python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
October 05, 2020 - 12:58:48
Django version 3.1, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
这是终端中的输出:
pipenv shell
pipenv install
python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
October 05, 2020 - 12:58:48
Django version 3.1, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
当我尝试在网站中创建帐户时,它出现以下错误:
OperationalError at /accounts/signup/
no such table: accounts_customuser
要解决此问题,我尝试运行以下命令:
python manage.py makemigrations
python manage.py migrate
它是成功的,并给出了以下输出:
No changes detected
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
但是,当我尝试创建帐户时,仍然会出现相同的错误:
OperationalError at /accounts/signup/
no such table: accounts_customuser
accounts应用程序中没有migrations文件夹,因此我只迁移了accounts应用程序:
python manage.py makemigrations accounts
Migrations for 'accounts':
accounts/migrations/0001_initial.py
- Create model CustomUser
├── admin.py
├── apps.py
├── forms.py
├── __init__.py
├── migrations
│ ├── 0001_initial.py
│ └── __init__.py
├── models.py
├── tests.py
├── urls.py
└── views.py
python manage.py迁移帐户
引发错误:
python manage.py migrate accounts
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before
its dependency accounts.0001_initial on database 'default'.
我不明白为什么会出现这些错误,以及我应该如何修复它们
这是我的帐户应用程序的结构:
python manage.py makemigrations accounts
Migrations for 'accounts':
accounts/migrations/0001_initial.py
- Create model CustomUser
├── admin.py
├── apps.py
├── forms.py
├── __init__.py
├── migrations
│ ├── 0001_initial.py
│ └── __init__.py
├── models.py
├── tests.py
├── urls.py
└── views.py
这是0001_initial.py
中的代码:
# Generated by Django 3.1 on 2020-10-05 13:01
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
migrations.CreateModel(
name='CustomUser',
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')),
('age', models.PositiveIntegerField(blank=True, null=True)),
('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()),
],
),
]
非常感谢你的帮助