TypeError:int()参数必须是字符串,类字节对象或数字,而不是datetime.datetime
好的..我删除了完整的数据库。 EVEN重启我的电脑。
Models.py
from django.db import models
from django.core.urlresolvers import reverse
class Register(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
username = models.CharField(max_length=50)
password = models.CharField(max_length=50)
confirm_password = models.CharField(max_length=50)
email = models.EmailField(max_length=100)
position = models.CharField(max_length=50)
def get_absolute_url(self):
return reverse('user:register', kwargs={'pk': self.pk})
class Login(models.Model):
username = models.CharField(max_length=50)
password = models.CharField(max_length=50)
def __str__(self):
login = {'username': self.username, 'password': self.password}
return login
我没有设置主键或外键,但它仍然困扰着我。 我搜索并尝试了其他选项,但仍然无法找出问题和解决方案。 makemigrations没有给出错误,但是migrate命令给出了。
完整筹码:
D:\Python Projects\Project_Management>python manage.py makemigrations user
No changes detected in app 'user'
D:\Python Projects\Project_Management>python manage.py migrate
Operations to perform:
Apply all migrations: contenttypes, admin, sessions, auth, user
Running migrations:
Rendering model states... DONE
Applying user.0003_auto_20160911_0013...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 349, in execute_from_command_line
utility.execute()
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 341, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 290, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 339, in execute
output = self.handle(*args, **options)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\migrate.py", line 177, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\operations\fields.py", line 62, in database_forwards
field,
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 382, in add_field
definition, params = self.column_sql(model, field, include_default=True)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 145, in column_sql
default_value = self.effective_default(field)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 210, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\models\fields\related.py", line 904, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\models\fields\__init__.py", line 736, in get_db_prep_save
prepared=False)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\models\fields\__init__.py", line 979, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\Vic\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\models\fields\__init__.py", line 987, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'Project',
'USER': 'postgres',
'PASSWORD': 'vikram',
'HOST': '127.0.0.1',
'PORT': '5433',
}
}
manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Project_Management.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
0003_auto_20160911_0013.py
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-09-10 18:43
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
import django.db.models.deletion
from django.utils.timezone import utc
class Migration(migrations.Migration):
dependencies = [
('user', '0002_auto_20160910_1740'),
]
operations = [
migrations.RemoveField(
model_name='login',
name='id',
),
migrations.RemoveField(
model_name='register',
name='id',
),
migrations.AddField(
model_name='login',
name='user_id',
field=models.ForeignKey(default=datetime.datetime(2016, 9, 10, 18, 43, 28, 263522, tzinfo=utc), on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='login_id', serialize=False, to='user.Register'),
preserve_default=False,
),
migrations.AddField(
model_name='register',
name='user_id',
field=models.IntegerField(default=1, primary_key=True, serialize=False),
preserve_default=False,
),
migrations.AlterField(
model_name='login',
name='password',
field=models.CharField(max_length=50),
),
migrations.AlterField(
model_name='login',
name='username',
field=models.CharField(max_length=50),
),
migrations.AlterField(
model_name='register',
name='username',
field=models.CharField(max_length=50),
),
]
我创建了全新的数据库.. 请帮忙.. 提前谢谢。
答案 0 :(得分:4)
您要将 this.stop();
///////////////////////////////////////////////////////////////////////////////////////////////////////
// gestion du temps
///////////////////////////////////////////////////////////////////////////////////////////////////////
this.leTimeOut = window.setTimeout(punir.bind(this), 31000);
this.lInterval = window.setInterval(afficherTemps.bind(this), 1000);
/////////////////////////
Cutted section
////////////////////////
console.info("!!! "+nbMatchs+" !!!");
this.txtItems.text = ""+(6-nbMatchs);
if(nbMatchs == 6){
window.clearTimeout(this.leTimeOut);
this.gotoAndStop("FinNiveau1");
}
return bonnePosition;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction pour lancer la punition
///////////////////////////////////////////////////////////////////////////////////////////////////////
function punir(evt){
console.log("temps écoulé");
this.gotoAndStop("EchecNiveau1");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction d'affichage du temps
///////////////////////////////////////////////////////////////////////////////////////////////////////
this.txtTimer.text = "29";
function afficherTemps(evt){
this.txtTimer.text = parseInt(this.txtTimer.text)-1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Fonction et écouteur du bouton Annuler
///////////////////////////////////////////////////////////////////////////////////////////////////////
this.btRetour.evenementClick = this.btRetour.on("click", onClicA);
function onClicA(evt) {
console.log("retour au menu");
clearTimeOut(this.leTimeOut);
evt.remove(); //retrait de l'écouteur (la méthode facile!)
this.parent.gotoAndStop("Intro");
}
的默认值定义为ForeignKey
个对象。 datetime
应该是ForeignKey
,表示其他某个表的ID。
问题在于这段代码
Integer
更具体地说,
migrations.AddField(
model_name='login',
name='user_id',
field=models.ForeignKey(default=datetime.datetime(2016, 9, 10, 18, 43, 28, 263522, tzinfo=utc), on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='login_id', serialize=False, to='user.Register'),
preserve_default=False,
),
将field=models.ForeignKey(default=datetime.datetime(2016, 9, 10, 18, 43, 28, 263522, tzinfo=utc), on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='login_id', serialize=False, to='user.Register')
参数更改为您引用的default
所代表的行的ID
的值。