我已在Cluster
修改了models.py
模型,以添加以下字段:
name = models.CharField(max_length=300, default="")
FAILED = 'FL'
RUNNING = 'RN'
SUCCESS = 'SC'
STATUS = (
(FAILED, 'FAILED'),
(RUNNING, 'RUNNING'),
(SUCCESS, 'SUCCESS'),
)
status = models.CharField(max_length=2,
choices=STATUS,
default=FAILED)
def save(self, *args, **kwargs):
'''
Override the original save's method. It now saves
when the cluster was created.
Attributes:
-----------
*args: a pointer list to all the objects of
the Cluster's class.
**kwargs: the data of each object.
'''
self.created = timezone.now()
self.deleted = timezone.now()
# call the "real" save
super(Cluster, self).save(*args, **kwargs)
所以,当我继续迁移数据库时,我得到了以下错误:
dglab2:cluster_admin philippe$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, clusters, contenttypes, auth, sessions
Running migrations:
Applying clusters.0006_auto_20141001_0028...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/philippe/django/django/core/management/__init__.py", line 336, in execute_from_command_line
utility.execute()
File "/Users/philippe/django/django/core/management/__init__.py", line 328, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/philippe/django/django/core/management/base.py", line 359, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/philippe/django/django/core/management/base.py", line 409, in execute
output = self.handle(*args, **options)
File "/Users/philippe/django/django/core/management/commands/migrate.py", line 159, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/Users/philippe/django/django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "/Users/philippe/django/django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "/Users/philippe/django/django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "/Users/philippe/django/django/db/migrations/operations/fields.py", line 131, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/Users/philippe/django/django/db/backends/schema.py", line 509, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict)
File "/Users/philippe/django/django/db/backends/schema.py", line 671, in _alter_field
params,
File "/Users/philippe/django/django/db/backends/schema.py", line 98, in execute
cursor.execute(sql, params)
File "/Users/philippe/django/django/db/backends/utils.py", line 78, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/philippe/django/django/db/backends/utils.py", line 63, in execute
return self.cursor.execute(sql, params)
File "/Users/philippe/django/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/philippe/django/django/db/backends/utils.py", line 63, in execute
return self.cursor.execute(sql, params)
File "/Users/philippe/django/django/db/backends/mysql/base.py", line 128, in execute
return self.cursor.execute(query, args)
File "/Library/Python/2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.DataError: (1265, "Data truncated for column 'status' at row 1")
我的Django版本为1.8.dev
。我深入研究了这个问题,但我还没有找到它的根源。有人可以帮帮我吗?
这是迁移产生的SQL
:
dglab2:cluster_admin philippe$ python manage.py sqlmigrate clusters 0001
BEGIN;
CREATE TABLE `clusters_cluster` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `size` integer NOT NULL);
CREATE TABLE `clusters_data` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `filename` varchar(300) NOT NULL);
CREATE TABLE `clusters_databaserepo` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` varchar(60) NOT NULL);
CREATE TABLE `clusters_dgsecure` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `version` varchar(100) NOT NULL, `database_id` integer NOT NULL);
CREATE TABLE `clusters_hadoopdistributor` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` varchar(100) NOT NULL);
CREATE TABLE `clusters_hadoopversion` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `version` varchar(100) NOT NULL, `distributor_id` integer NOT NULL);
CREATE TABLE `clusters_user` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `username` varchar(300) NOT NULL, `password` varchar(300) NOT NULL);
CREATE TABLE `clusters_cluster_datafiles` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `cluster_id` integer NOT NULL, `data_id` integer NOT NULL, UNIQUE (`cluster_id`, `data_id`));
ALTER TABLE `clusters_cluster` ADD COLUMN `dgsecure_id` integer NOT NULL;
ALTER TABLE `clusters_cluster` ALTER COLUMN `dgsecure_id` DROP DEFAULT;
ALTER TABLE `clusters_cluster` ADD COLUMN `hadoop_dist_id` integer NOT NULL;
ALTER TABLE `clusters_cluster` ALTER COLUMN `hadoop_dist_id` DROP DEFAULT;
ALTER TABLE `clusters_cluster` ADD COLUMN `hadoop_version_id` integer NOT NULL;
ALTER TABLE `clusters_cluster` ALTER COLUMN `hadoop_version_id` DROP DEFAULT;
ALTER TABLE `clusters_cluster` ADD COLUMN `user_id` integer NOT NULL;
ALTER TABLE `clusters_cluster` ALTER COLUMN `user_id` DROP DEFAULT;
CREATE INDEX clusters_dgsecure_c9eff1bf ON `clusters_dgsecure` (`database_id`);
ALTER TABLE `clusters_dgsecure` ADD CONSTRAINT cluster_database_id_2416eb8a667195f0_fk_clusters_databaserepo_id FOREIGN KEY (`database_id`) REFERENCES `clusters_databaserepo` (`id`);
CREATE INDEX clusters_hadoopversion_069bf3f9 ON `clusters_hadoopversion` (`distributor_id`);
ALTER TABLE `clusters_hadoopversion` ADD CONSTRAINT D1029f1c135de154866e863b88d739fa FOREIGN KEY (`distributor_id`) REFERENCES `clusters_hadoopdistributor` (`id`);
CREATE INDEX clusters_cluster_datafiles_a97b1c12 ON `clusters_cluster_datafiles` (`cluster_id`);
ALTER TABLE `clusters_cluster_datafiles` ADD CONSTRAINT clusters_clus_cluster_id_5fddd1f16a0f42c3_fk_clusters_cluster_id FOREIGN KEY (`cluster_id`) REFERENCES `clusters_cluster` (`id`);
CREATE INDEX clusters_cluster_datafiles_a565e755 ON `clusters_cluster_datafiles` (`data_id`);
ALTER TABLE `clusters_cluster_datafiles` ADD CONSTRAINT clusters_cluster_dat_data_id_42d06973460b90a_fk_clusters_data_id FOREIGN KEY (`data_id`) REFERENCES `clusters_data` (`id`);
CREATE INDEX clusters_cluster_489be2b3 ON `clusters_cluster` (`dgsecure_id`);
ALTER TABLE `clusters_cluster` ADD CONSTRAINT clusters_cl_dgsecure_id_7410c428d00a7fa8_fk_clusters_dgsecure_id FOREIGN KEY (`dgsecure_id`) REFERENCES `clusters_dgsecure` (`id`);
CREATE INDEX clusters_cluster_151522ef ON `clusters_cluster` (`hadoop_dist_id`);
ALTER TABLE `clusters_cluster` ADD CONSTRAINT D0d423c7841eab73afb26302066d787b FOREIGN KEY (`hadoop_dist_id`) REFERENCES `clusters_hadoopdistributor` (`id`);
CREATE INDEX clusters_cluster_f48b3f48 ON `clusters_cluster` (`hadoop_version_id`);
ALTER TABLE `clusters_cluster` ADD CONSTRAINT hadoop_version_id_37ed611b8d8319f4_fk_clusters_hadoopversion_id FOREIGN KEY (`hadoop_version_id`) REFERENCES `clusters_hadoopversion` (`id`);
CREATE INDEX clusters_cluster_e8701ad4 ON `clusters_cluster` (`user_id`);
ALTER TABLE `clusters_cluster` ADD CONSTRAINT clusters_cluster_user_id_34b94e57c0e18ed5_fk_clusters_user_id FOREIGN KEY (`user_id`) REFERENCES `clusters_user` (`id`);
COMMIT;