Djangoのデータベース操作関連のエラーMySQLアクセス(RPM)ユーザールート@ localhostのエラーソリューション概要については拒否されました

 

問題:エラーは、属性フィールドを変更発生しました

1>

>python manage.py makemigrations
You are trying to add a non-nullable field 'price_monthly' to product without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 1) Provide a one-off default now (will be set on all existing rows) 2) Quit, and let me add a default in models.py Select an option: 

{モデルが非空のフィールドを追加した後、これは以前に、テーブル内のレコードを作成することができるが、既存のレコードは、この値を持っていません}

 

2>

 

>python manage.py migrate
... ...
raise errorclass(errno, errorvalue)django.db.utils.ProgrammingError: (1146, "Table 'lab_data.bigdata_postgraduate_research_directions' doesn't exist")

{=ブランクTrueまたはヌルを加えるためである=分野で真の原因}

 

 

3>

>python manage.py makemigrations
デフォルトのない非NULL可能に教授にNULL可能フィールド「のjob_title」を変更しようとしています。我々は(データベースが既存の行を移入するために何かを必要とする)ことはできません。
修正を選択してください:
 1)一回限りのデフォルトは、現在(既存のすべての行に設定されます)の提供
 2)今のところ無視し、私はNULLで自分自身を既存の行を処理させる(例えば、新たな移行にRunPythonまたはRUNSQL操作を追加しますAlterField操作の前にファイル)
 3)終了し、私はmodels.pyでデフォルトを追加してみましょう
オプションを選択します。

{これは、削除されたヌル= Trueの後に生成された間違ったモデルです}

1>の理由を説明します。

単一の移行が複数のデータベースに適用することができるように、1移行システムが設計されています。たとえば、開発版、ステージングバージョン、および1つまたは複数の生産バージョンを持つことができます。だからこそだ作る  移行するとは異なるステップで  適用する  移行を、そしてなぜmakemgirations それが行を持っていないことを確認するために、現在アクティブなデータベースを見ることができません。あなたがしていたデータベースへの移行を適用するために何をしようか?

あなたのケースでの解決策は単純です:行がないことから、オプション1(すべての既存の行では、デフォルトの設定では)全く何もしません。だから、オプション1、あなたが好きな任意の値を選択してください。

[ Djangoの1.7.1は、フィールドのデフォルト値を必要とする-しかし、エントリがデータベースではありません。どうして?]

2. Djangoは、あなたのモデルに余分な「twitbot_id」を必要としない、すべてのモデルにデフォルトの「ID」フィールドを追加します。代理の主キーはあなたが必要とするすべてである場合、それは自動生成された「ID」の複製になりますので、「twitbot_id」を忘れます。参照してくださいhttps://docs.djangoproject.com/en/dev/topics/db/models/#automatic-primary-key-fieldsを

あなたはこれを追加し、すでにデータベース内のtwitterBOTオブジェクトを持っている場合は、データベース内の既存の行のために、この列を移入するためにデフォルト値を提供しなければなりません。

[ このエラーを失うように見えることはできません:「あなたは非NULL可能フィールドを追加しようとしています」 ]

後のテーブルの前に完了し、親、唯一のパスとしてテーブルBを作成するので、あなたが私に似ている場合は、テーブルが作成されているため、マイグレーションがあるだろうとき3、そして、ここでのデータは、そこにありますこのエラーは、デフォルト値がnull指定されていないことができない場合は、新しいテーブルが表示されます。

ソリューション:

1> bが、基本クラスに追加された空の許可またはデフォルト値を追加し、B(真=メタ抽象)セットのテーブルを構築しません。

クラスベース(models.Model):
    '' ' 
    类基
    ''' 
    タイトル= models.CharField(MAX_LENGTH = 150、ヌル= TRUE)
    含有量= models.TextField(ヌル= TRUE)
    、auto_now_add =真(TIME_STAMP = models.DateTimeFieldデフォルト= timezone.now())
    リンク= models.URLField(空白=真、verbose_name = 'URL_LINK')

    クラスのMeta:
        真=抽象

注意:DataTimeFieldは変更しないように、他のように見えるしていません!

1> 2> 3>

(フォルダ全体を削除せずに)すべての移行のファイルを削除し、しよう

 

 

質問:manytomanyfeildデフォルトなし

 

Djangoの管理者が警告「フィールド 『X』はデフォルト値を持っていない」を与えます

 

 

 

問題:エラーがメタプロパティを追加発生しました

 

InternalError(errnoに、errorvalue)上げる
django.db.utils.InternalErrorを:(1017、 "ファイルが見つかりません: '\\ \\ lab_data people_patent_prizes.frm'(errnoに:2 -いいえそのようなファイルまたはディレクトリ)")

{モデルクラス増加クラスメタ:DB_Tableの=「人」に対応するデータベーステーブルは、人に変更するように、破壊された元のテーブルの間の可能なリンク}
ソリューション:

 

(フォルダ全体を削除せずに)すべての移行のファイルを削除し、しよう

http://blog.csdn.net/pipisorry/article/details/45727309

 

質問:テーブルのフィールドは存在しません。

「『フィールドリスト』で不明な列 『名』」

ジャンゴテーブル教授を作成する人々のテーブルのフィールドを継承し、(データベースクエリを見ることができる)、バックグラウンドで見ることができますが、実際にデータベースに存在しません。

問題の原因:

編集フィールドでの1モデルが対応するテーブルで作成された(フィールドは、親クラスから継承されるに問題が原因であるかもしれないもの、見える?)のデータベースではありません

フィールド内のビューデータベーステーブル:

2.移行ファイルが間違って何ですか?データベースに同期まったくその結果ん(表が作成されませんでした)

解決策1:

追加のフィールドがデータベースに手動で作成されていません

テーブルを変更bigdata_professor列名VARCHAR(6)を追加します。

再びテーブルのフィールドを表示します。

Djangoのサーバが再び実行し、名前フィールドが間違っていないだろうときに、背景を追加します。

解決策2:

移行は、フォルダ全体を削除するには、その後、Pythonの  manage.py makemigrationsは、その後、Pythonは  移行をmanage.pyの


この表は、成功を再確立することができます!(Djangoは新しいテーブルbigdata_professorに問い合わせることができます....)


注意

最高の削除の成功の後1.前のフォルダの移行を再構築(中APP)

2.この問題を持っていないかもしれないだけで移行ファイルを削除します。

いいえ移行は適用されませんします。お使いのモデルがまだ移行に反映されていない、ので、適用されません変更を持っています。実行新しいマイグレーションを作るために「manage.py makemigrations」、およびそれらを適用するために、次に再実行「manage.py移行」。

私は、それが最初の操作を行っ移行する前に(makemigrations中)であってもよい、右側に操作を削除し、移行ファイルが問題になる理由を知っている、としていない、行くを持っていましたか?

[ Djangoのモデル(1054年、「 'フィールドリスト'内の不明列」) ]

 

 

質問:表が存在しないまたはNoマイグレーションを適用します

 

 「テーブル 『lab_data.bigdata_resdir』が存在しません」

新しいテーブルモデルを作成した後、成功をmakemigrationsが、エラーを移行します:

 

python manage.py migrate
Operations to ...:
Apply all migrations: ...
No migrations to apply.(即使实际上明明makemigrations成功,并且有许多migrations可以应用)
  Your models have changes that are not yet reflected in a migration, and so won't be applied.  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

按照提示重新makemigration后migration文件就不会创建新表了,在数据库中表也的确没有新建。

 

原因:

 

1. Sounds like your initial migration was faked because the table already existed (probably with an outdated schema):

https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps

"This will make a new initial migration for your app. Now, when you run migrate,Django will detect that you have an initial migration and that the tables it wants to create already exist, and will mark the migration as already applied."

Otherwise you would get an no-such-table error.

[No migrations to apply, even though there are migrations to apply]

2. 也可能是之前按照某个说明执行了一次python manage.py migrate --fake导致的。--fake 的含义是不执行该迁移脚本但是标记该脚本已经被执行过。导致之后无法正常进行迁移。

[Django 1.7 中 migrate 无法执行而且表不存在的解决方案]

解决方案:

方法1.

1> In MySQL Database delete row 'app_name' from the table 'django_migrations'.

打开mysql command line client, 进入创建好的数据库use databasename; 查看表select * from django_migration; 发现将要执行的迁移脚本的 id 已经添加在表中了,将其删除即可,即删除最新一次app_name对就的id行。

2> Delete all migration files in migrations folder.

3> Try again python manage.py makemigrations and python manage.py migrate command.

[Django 1.7 - “No migrations to apply” when run migrate after makemigrations]

 

方法2:

 

移除整个migrations文件夹,重新makemigrations和migrate。之后就会自动创建了:

方法3:

实在不行,只能drop database,再重新建立了。

http://blog.csdn.net/pipisorry/article/details/45727309

 

问题:外键修改成多对多错误

ValueError: Cannot alter field bigdata.Postgraduate.publisher into bigdata.Postgraduate.publisher - they are not compatible types (you cannot alter to or from M2M fields
, or add or remove through= on M2M fields)

{这个错误是由将模型Postgraduate中的publisher字段从ForeignKey修改成ManyToManyField引起的}

解决方案:

删除所有migrations文件,重新makemigrations和migrate

[foreignkey error: Django migration error :you cannot alter to or from M2M fields, or add or remove through= on M2M fields]

 

数据库注册到site管理错误

TypeError: __init__() missing 2 required positional arguments : 'model' and 'admin_site'

 

class DirectionsInline(inlineBase, admin.ModelAdmin):
    model = Directions
    inlines = [ImagesInline, ]
admin.site.register(Directions, DirectionsInline)

解决:原因可能是继承admin.ModelAdmin的类中不能有model = ***

 

 

 

数据库权限错误

 

django.db.utils.operationalerror:<1045,"access denied for user root@localhost using password yes>

解决方案1:django setting.py文件中设置的database用户名或者密码错了,修改一下就可以了

或者是django运行项目时用的不是settings.py文件,这个在os.environ.setdefault("DJANGO_SETTINGS_MODULE", "labsite.settings")中设置

其它方案

Access denied for user 'root'@'localhost' (using password: YES)

mysql Access denied for user root@localhost错误解决方法总结(转)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

MySQL Forums ::Install & Repo ::ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

django.db.utils.operationalerror:<2003, "can't connect to mysql server on '127.0.0.1'(winerror 10061] No connection could be made because the target machine actively refused it)")

settings.py中设置的host和port如下

'HOST': '127.0.0.1','PORT': '3306'

如改动port为其它,可能导致该问题

 

 

 

其它问题:

1.Error: Tablespace for table xxx exists. Please DISCARD the tablespace before IMPORT

2. django.db.utils.ProgrammingError: (1146, "Table 'lab_data.django_migrations' doesn't exist")

3.django.db.utils.InternalError: (1050, "Table '`l ab_data`.`django_migrations`'already exists")

1>两个模型的数据库表名设置成一样的了

class Meta:
    db_table = 'WorkExp1'

2>python manage.py migrate --fake

 

 

本文转自:http://blog.csdn.net/pipisorry/article/details/45727309

kingrain送给读者的话:Everthing isn't getting along well,your efforts paid off!

问题:字段修改属性发生错误

1>

>python manage.py makemigrations
You are trying to add a non-nullable field 'price_monthly' to product without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 1) Provide a one-off default now (will be set on all existing rows) 2) Quit, and let me add a default in models.py Select an option: 

{这个可能是之前已创建了表中的一条记录,之后模型中增加了一个非空的字段,但是原来已经存在的记录没有这个值}

 

2>

 

>python manage.py migrate
... ...
raise errorclass(errno, errorvalue)django.db.utils.ProgrammingError: (1146, "Table 'lab_data.bigdata_postgraduate_research_directions' doesn't exist")

{这个是因为在字段中添加了blank=True或者 null=True引起的}

 

 

3>

>python manage.py makemigrations
You are trying to change the nullable field 'job_title' on professor to non-nullable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows)
 2) Ignore for now, and let me handle existing rows with NULL myself (e.g. adding a RunPython or RunSQL operation in the new migration file before the AlterField operation)
 3) Quit, and let me add a default in models.py
Select an option:

{这个是将模型中的null=True删除了之后产生的错误}

1>原因解释:

1. The migrations system is designed so that a single migration can be applied to more than one database. For example, you could have a development version, a staging version, and one or more production versions. That's whymaking the migration is a distinct step from applying the migration, and whymakemgirations can't just look at the currently active database to see that it doesn't have any rows. What if you then try to apply the migration to a database that does?

The solution in your case is simple: since there are no rows, option 1 (setting a default on all existing rows) won't do anything at all. So choose option 1, and any value you like.

[Django 1.7.1 requires a Default value for field - but no entry is in database. Why?]

2. Django adds a default "id" field to every model, you don't need an extra "twitbot_id" in your model. If a surrogate primary key is all you need, forget about "twitbot_id" because it will be a duplicate of the auto-generated "id". Seehttps://docs.djangoproject.com/en/dev/topics/db/models/#automatic-primary-key-fields

If you add this and you already have TwitterBot objects in your database you must provide a default value to populate this column for existing rows in the database.

[Can't seem to lose this error: “You are trying to add a non-nullable field”]

3. 如果你跟我一样是因为之前建好表a后,又创建一个表b作为a的父类,a中只有pass,那么因为表a已经创建,其中有数据,当a迁移时就会出现新表不能为null且没有指定默认值时就会出现这种错误。

解决方案:

1>在基类b中添加允许为空或者添加默认值,并设置b不建表(meta中的abstract = true)

class Base(models.Model):
    '''
    基类
    '''
    title = models.CharField(max_length=150, null=True)
    content = models.TextField(null=True)
    time_stamp = models.DateTimeField(auto_now_add=True, default=timezone.now())
    link = models.URLField(blank=True, verbose_name='url_link')

    class Meta:
        abstract = True

Note:DataTimeField好像与其它的不一样,不好改!

1>2>3>

删除所有migrate文件(不用移除整个文件夹),然后重来

 

 

问题:manytomanyfeild没有默认值

 

django admin gives warning “Field 'X' doesn't have a default value”

 

 

 

问题:添加元属性发生错误

 

raise InternalError(errno, errorvalue)
django.db.utils.InternalError: (1017, "Can't find file: '.\\lab_data\\people_patent_prizes.frm' (errno: 2 -No such file or directory)")

{模型类中增加class Meta:db_table='People'使数据库中对应的表名修改成了People,原来的表间联系可能破坏了}
解决方案:

 

删除所有migrate文件(不用移除整个文件夹),然后重来

http://blog.csdn.net/pipisorry/article/details/45727309

 

问题:表中字段不存在

"Unknown column 'name' in 'field list'"

django中创建了表professor继承了表people的字段,并且在后台可以看到,但实际在数据库中不存在(数据库中查询可看到)

出现问题原因:

1. model中编辑的字段没有在数据库对应的表里创建(原因可能是字段是继承自父类,出现的什么问题?)

数据库中查看表中的字段:

2. migration文件出了什么问题?导致没有同步到数据库(表都没创建)

解决方案1:

在数据库中手动添加没有创建的字段

alter table bigdata_professor add column name varchar(6);

再次查看表中字段:

再次运行django服务器,后台添加name字段时就不会出错了。

解决方案2:

先删除整个migrations文件夹,再Python manage.py makemigrations,再python manage.py migrate


这样表就可以重新建立成功了!(可以查询到django中新建的表bigdata_professor....)


Note:

1. 成功后最好把之前删除的文件夹migrations重新建一个(app中的)

2. 只删除migration文件可能不会出现这个问题:

No migrations to apply.   Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

我了个去,都不知道为啥migration文件会出问题,删除后再操作就没事了,可能是(在makemigrations)之前先进行了migrate操作?

[Django Models (1054, “Unknown column in 'field list'”)]

 

 

问题:表不存在或者No migrations to apply

 

 "Table 'lab_data.bigdata_resdir' doesn't exist"

模型中建立新表后,makemigrations成功,但是migrate出现错误:

 

python manage.py migrate
Operations to ...:
Apply all migrations: ...
No migrations to apply.(即使实际上明明makemigrations成功,并且有许多migrations可以应用)
  Your models have changes that are not yet reflected in a migration, and so won't be applied.  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

按照提示重新makemigration后migration文件就不会创建新表了,在数据库中表也的确没有新建。

 

原因:

 

1. Sounds like your initial migration was faked because the table already existed (probably with an outdated schema):

https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps

"This will make a new initial migration for your app. Now, when you run migrate,Django will detect that you have an initial migration and that the tables it wants to create already exist, and will mark the migration as already applied."

Otherwise you would get an no-such-table error.

[No migrations to apply, even though there are migrations to apply]

2. 也可能是之前按照某个说明执行了一次python manage.py migrate --fake导致的。--fake 的含义是不执行该迁移脚本但是标记该脚本已经被执行过。导致之后无法正常进行迁移。

[Django 1.7 中 migrate 无法执行而且表不存在的解决方案]

解决方案:

方法1.

1> In MySQL Database delete row 'app_name' from the table 'django_migrations'.

打开mysql command line client, 进入创建好的数据库use databasename; 查看表select * from django_migration; 发现将要执行的迁移脚本的 id 已经添加在表中了,将其删除即可,即删除最新一次app_name对就的id行。

2> Delete all migration files in migrations folder.

3> Try again python manage.py makemigrations and python manage.py migrate command.

[Django 1.7 - “No migrations to apply” when run migrate after makemigrations]

 

方法2:

 

移除整个migrations文件夹,重新makemigrations和migrate。之后就会自动创建了:

方法3:

实在不行,只能drop database,再重新建立了。

http://blog.csdn.net/pipisorry/article/details/45727309

 

问题:外键修改成多对多错误

ValueError: Cannot alter field bigdata.Postgraduate.publisher into bigdata.Postgraduate.publisher - they are not compatible types (you cannot alter to or from M2M fields
, or add or remove through= on M2M fields)

{这个错误是由将模型Postgraduate中的publisher字段从ForeignKey修改成ManyToManyField引起的}

解决方案:

删除所有migrations文件,重新makemigrations和migrate

[foreignkey error: Django migration error :you cannot alter to or from M2M fields, or add or remove through= on M2M fields]

 

数据库注册到site管理错误

TypeError: __init__() missing 2 required positional arguments : 'model' and 'admin_site'

 

class DirectionsInline(inlineBase, admin.ModelAdmin):
    model = Directions
    inlines = [ImagesInline, ]
admin.site.register(Directions, DirectionsInline)

解决:原因可能是继承admin.ModelAdmin的类中不能有model = ***

 

 

 

数据库权限错误

 

django.db.utils.operationalerror:<1045,"access denied for user root@localhost using password yes>

解决方案1:django setting.py文件中设置的database用户名或者密码错了,修改一下就可以了

或者是django运行项目时用的不是settings.py文件,这个在os.environ.setdefault("DJANGO_SETTINGS_MODULE", "labsite.settings")中设置

其它方案

Access denied for user 'root'@'localhost' (using password: YES)

mysql Access denied for user root@localhost错误解决方法总结(转)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

MySQL Forums ::Install & Repo ::ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

django.db.utils.operationalerror:<2003, "can't connect to mysql server on '127.0.0.1'(winerror 10061] No connection could be made because the target machine actively refused it)")

settings.py中设置的host和port如下

'HOST': '127.0.0.1','PORT': '3306'

如改动port为其它,可能导致该问题

 

 

 

其它问题:

1.Error: Tablespace for table xxx exists. Please DISCARD the tablespace before IMPORT

2. django.db.utils.ProgrammingError: (1146, "Table 'lab_data.django_migrations' doesn't exist")

3.django.db.utils.InternalError: (1050, "Table '`l ab_data`.`django_migrations`'already exists")

1>二つのモデルのデータベーステーブル名が同一に設定されています

クラスメタ:
    DB_Tableの= 'WorkExp1'

2>のpython manage.pyは--fakeを移行します

 

 

これは、スイッチ:http://blog.csdn.net/pipisorry/article/details/45727309

おすすめ

転載: www.cnblogs.com/HHHAI/p/11248265.html