TypeError: int() argument must be a string, a bytes-like object or a number, not datetime.datetime
<p>TypeError: int() argument must be a string, a bytes-like object or a number, not datetime.datetime</p>

<p>Okay.. I deleted complete database. EVEN Restarted My PC.</p>

<p>Models.py</p>

<pre><code>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
</code></pre>

<p>I am not setting primary key nor foreign key but still it's bugging me.
I searched and tried other options but can't still figure out problem and solution.
makemigrations doesn't give an error but migrate command gives.</p>

<p>Full Stack :</p>

<pre><code>D:\Python Projects\Project_Management&gt;python manage.py makemigrations user
No changes detected in app 'user'
D:\Python Projects\Project_Management&gt;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 &lt;module&gt;
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'
</code></pre>

<p>settings.py</p>

<pre><code>DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': 'Project',
    'USER': 'postgres',
    'PASSWORD': 'vikram',
    'HOST': '127.0.0.1',
    'PORT': '5433',
}
}
</code></pre>

<p>manage.py</p>

<pre><code>#!/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)
</code></pre>

<p>0003_auto_20160911_0013.py</p>

<pre><code># -*- 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),
    ),
]
</code></pre>

<p>I created whole new database..
Please help..
Thanks in advance.</p>

<p>You are defining a <strong>default</strong> value of a <code>ForeignKey</code> to be a <code>datetime</code> object. A <code>ForeignKey</code> should be an <code>Integer</code> representing the ID of some other table.</p>

<p>The problem is in this piece of code</p>

<pre><code>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,
),
</code></pre>

<p>More specifically,   </p>

<pre><code>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')
</code></pre>

<p>change the <code>default</code> argument to be the value of the <code>ID</code> of the row represented by that <code>datetime</code> you referenced.</p>

python django datetime typeerror